Usually I find LyzandeR's answers to be helpful. This time not as much. The question posed an error message that was obviously not from the Hmisc::units<-
function, because it did not occur with the first instance of units(fail.time) <- "Day"
but rather occurred after the pkg:sf was loaded. If you look at the DESCRIPTION file for sf
you find that it has Imports:units
. In point of fact, then, it was units::unit<-.numeric
that was throwing the initial cryptic error. If you restart R with only Hmisc (and not sf) loaded, you see that there are only two units<-
methods:
> methods(`units<-`)
[1] units<-.default units<-.difftime
see '?methods' for accessing help and source code
If you load the sf package you can now see that it is the (newly loaded) units::units<-.numeric
function that is throwing the error because that package was loaded by sf
and because there was not actually a pre-existing .numeric
version of the function, there was a resultant "masking" (perhaps more accurately a "diversion") of the existing function's domain and there was no automatically generated warning.
> library(sf)
Linking to GEOS 3.6.1, GDAL 2.1.3, proj.4 4.9.3
> methods(`units<-`)
[1] units<-.default units<-.difftime units<-.numeric* units<-.units*
see '?methods' for accessing help and source code
> getAnywhere(`units<-.numeric`)
A single object matching ‘units<-.numeric’ was found
It was found in the following places
registered S3 method for units<- from namespace units
namespace:units
with value
function (x, value)
{
stopifnot(inherits(value, "units") || inherits(value, "symbolic_units"))
if (inherits(value, "units"))
value <- units(value)
attr(x, "units") = value
class(x) <- "units"
x
}
<environment: namespace:units>
The package's maintainer is now aware that some of us are having puzzlement:
maintainer('sf')
[1] "Edzer Pebesma <edzer.pebesma@uni-muenster.de>"