Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Documenting setAs() and setOldClass() with Roxygen

Tags:

r

roxygen2

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")
like image 309
dholstius Avatar asked Oct 13 '11 18:10

dholstius


1 Answers

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.

like image 143
Triad sou. Avatar answered Oct 04 '22 06:10

Triad sou.