-
Notifications
You must be signed in to change notification settings - Fork 236
Description
The documentation for setClass
explains that the function returns a class generator object, which can be invoked like new
, but since it's an actual function it can be accessed via the ::
operator, and therefore offers safety and convenience to users. BioConductor do something like this by defining their own constructor functions, but I see the return value of setClass
as R's convenient, built-in version of that.
Unfortunately, though, roxygen2 doesn't allow you to export this generator function automatically. If you add an @export
to the setClass
statement, it only exports the class itself, via exportClass
:
R/my_class.R
:
#' @export
MyClass = setClass('MyClass', representation(foo='numeric'))
NAMESPACE
:
exportClasses(MyClass)
If try to later annotate an @export
onto the return value, but separately from the exportClass
, Roxygen generates a blank export statement:
R/my_class.R
:
#' @export
MyClass = setClass('MyClass', representation(foo='numeric'))
#' @export
MyClass
NAMESPACE
:
export()
exportClasses(MyClass)
The NAMESPACE
file that I actually want to be generated is
export(MyClass)
exportClasses(MyClass)
As a package developer, I would appreciate a new tag (say @exportConstructor
), to do this automatically, or else some kind of workaround that allows me to generate the above NAMESPACE
using Roxygen, instead of adding it manually.