I’m developing a package that provides an S3 class named “Foo”. It also provides an “as” method for coercing it to (someone else’s) S4 class named “Bar”. My code looks like this:
#' ...
setOldClass("Foo")
#' ...
setAs("Foo", "SpatialPointsDataFrame", function(from) {
# do stuff and return a SpatialPointsDataFrame
})
edit I’ve tried this:
#' ...
#' @name as
#' @export
setAs("Foo", "SpatialPointsDataFrame", function(from) {
# do stuff and return a SpatialPointsDataFrame
})
but then I get this from R CMD CHECK:
checking whether the name space can be loaded with stated dependencies … WARNING
Error in namespaceExport(ns, exports) : undefined exports: as
Calls: loadNamespace -> namespaceExport
Execution haltedA namespace must be able to be loaded with just the base namespace loaded: otherwise if the namespace gets loaded by a saved object, the session will be unable to start.
Probably some imports need to be declared in the NAMESPACE file.
in a separate .R file, I have:
#' @importClassesFrom sp SpatialPointsDataFrame
I’m using hadley’s devtools package, so I guess it’s roxygen2. This is what I do:
R> document("MyPackage")
The roxygen2 parser didn’t parse
setOldClass()andsetAs().We need to obtain appropriate
@nametags.I don’t know about the
setAs()function in detail, but theas()function is loaded from the methods package.So, I think that we don’t need
export(as)entry in NAMESPACE.