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 halted
A 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()
and setAs()
.
We need to obtain appropriate @name
tags.
#' "Foo" class
#'
#' @name Foo-class
#' @aliases Foo
#' @family Foo
#'
#' @exportClass Foo
setOldClass("Foo")
#' As("Foo", "SpatialPointsDataFrame")
#'
#' @name as
#' @family Foo
#'
#' @importClassesFrom sp SpatialPointsDataFrame
setAs("Foo", "SpatialPointsDataFrame", function(from) {
# do stuff and return a SpatialPointsDataFrame
})
I don't know about the setAs()
function in detail, but the as()
function is loaded from the methods package.
So, I think that we don't need export(as)
entry in NAMESPACE.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With