Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export S4 class generator function #1216

Closed
multimeric opened this issue Mar 31, 2021 · 1 comment · Fixed by #1396
Closed

Export S4 class generator function #1216

multimeric opened this issue Mar 31, 2021 · 1 comment · Fixed by #1396
Labels
feature a feature request or enhancement namespace 👩‍🚀

Comments

@multimeric
Copy link

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.

@multimeric multimeric changed the title Export R4 class generator function Export S4 class generator function Apr 8, 2021
@hadley hadley added feature a feature request or enhancement namespace 👩‍🚀 labels Apr 16, 2021
@hadley
Copy link
Member

hadley commented Jul 10, 2022

Minimal reprex:

library(roxygen2)

roc_proc_text(namespace_roclet(), "
#' @export
MyClass = setClass('MyClass', representation(foo='numeric'))"
)
#> [1] "exportClasses(MyClass)"

Created on 2022-07-10 by the reprex package (v2.0.1)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature a feature request or enhancement namespace 👩‍🚀
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants