It appears that the order of loading packages matters when using Rscript with the sf library.
library(sf)
library(methods)
showMethods("coerce")
will not contain
from="sf", to="Spatial"
from="Spatial", to="sf"
in the output, and the function as(x, "Spatial)
cannot be used
however
library(methods)
library(sf)
showMethods("coerce")
will contain the desired methods.
If using R console the problem does not occur as that loads the package methods
by default.
Is this due to an error in the sf package?
It seems brittle and undesirable to have to library(methods) first in every script, and also this could not be the only situation where this is a problem. Is there a general way to avoid having order matter when loading R packages?