Skip to content
New issue

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

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

Already on GitHub? # to your account

Rcpp packages FAILS when using roxygen2 to handle NAMESPACE (correction - this is not a bug - issue closed) #130

Closed
talgalili opened this issue Aug 17, 2013 · 7 comments

Comments

@talgalili
Copy link

If building an Rcpp package (using rcpp.package.skeleton will do),
And turning on:
build tools -> generate documentation with roxygen -> configure -> use roxygen to generate -> NAMESPACE files

Will cause roxygen to erase the following two ESSENTIAL lines from NAMESPACE:
useDynLib(PkgName)
exportPattern("^[[:alpha:]]+")

This will cause an error of the style:
Error in .Call("RcppDend_Rcpp_labels_dendrogram", PACKAGE = "RcppDend") :
"RcppDend_Rcpp_labels_dendrogram
" not available for .Call() for package "RcppDend"

I will also submit this report in the roxygen repo.

Thanks :)
Tal

@hadley
Copy link
Member

hadley commented Aug 17, 2013

This is not a roxygen2 bug - you either need to use package skeleton or supply the correct roxygen2 tags. You can't do both.

@talgalili
Copy link
Author

Thanks Hadley.
What roxygen2 tags do I need to use, and where, in order to not have the lines:
useDynLib(PkgName)
exportPattern("^[[:alpha:]]+")
Removed when I set roxygen2 to edit NAMESPACE?

p.s: the package was started using RStudio projects - where I asked for a package+Rcpp type project. But either way, this "feature" persists regardless.

@jjallaire
Copy link

See the roxygen2 documentation:

http://cran.r-project.org/web/packages/roxygen2/roxygen2.pdf

The exportPattern is a global wildcard that exports all functions that start with an alpha character (excluding ones that e.g. start with .). With roxygen2 you would explicitly export functions using roxygen2 directives. Note that this also works for C++ functions. See this documentation:

http://cran.rstudio.com/web/packages/Rcpp/vignettes/Rcpp-attributes.pdf

@talgalili
Copy link
Author

Hello JJ,
Thank you for the quick (and detailed) reply, here and on github.
I'm also responding to your remark here:
http://support.rstudio.org/help/discussions/problems/8418-rcpp-packages-fails-when-using-roxygen2-to-handle-namespace

Just to be precise - I did not add "user created code" to the NAMESPACE.
The Rcpp workflow did that automatically (without me knowing it, until things didn't work).
The steps I took were:

  1. Start an RStudio project of a package+Rcpp
  2. Turn roxygen2 NAMESPACE editing on
  3. Realizing that feature number 2 is not compatible with feature number 1.

Suggestions:

  1. Either have roxygen2 NAMESPACE editing have an exception for the code added by Rcpp (which, after reading you on github, wouldn't be needed), or

  2. If an RStudio project is of type package+Rcpp, issue a warning for (or even block the user from) having roxygen2 edit the NAMESPACE (which seems more reasonable).

  3. Not tell the user anything, and hope he will find this thread when searching why .Call fails, even that he had turned NAMESPACE editing on. :)

or, after another thought
4) Have roxygen2 NAMESPACE editing - also respect the
// [[Rcpp::export]]
tag, as a token to add that function to the NAMESPACE file (Which is what I had thought it is doing to begin with, but just now realized there is probably an extra tag needed for that in the .cpp file).

I hope what I'm saying makes sense...
Tal

@jjallaire
Copy link

I think the core issue is that before using/enabling these tools you need to first understand a bit more about what they do and how they work. In particular, turning roxygen2 namespace editing on implies that:

  1. You know what a NAMESPACE file is and you want it automatically generated (overwriting whatever was previously on disk)
  2. You are aware of the roxygen2 directives that impact the NAMESPACE file (e.g. @useDynlib and @export)

I agree that some users will get hung up here, but better that users understand how to use the tools thoroughly in the first place rather than providing a crutch in the form of special case warnings or other "automagic" workarounds.

@talgalili
Copy link
Author

Thanks JJ,
I think I understand better now.

I see some good comments where made here:
http://support.rstudio.org/help/discussions/questions/1495-rcpp-and-roxygen
And:
http://cran.r-project.org/web/packages/Rcpp/vignettes/Rcpp-attributes.pdf

I stand corrected about the "bug".

@jjallaire
Copy link

Okay, glad you've got everything working now!

On Saturday, August 17, 2013, Tal Galili wrote:

Thanks JJ,
I think I understand better now.

I see some good comments where made here:
http://support.rstudio.org/help/discussions/questions/1495-rcpp-and-roxygen
And:
http://cran.r-project.org/web/packages/Rcpp/vignettes/Rcpp-attributes.pdf

I stand corrected about the "bug".


Reply to this email directly or view it on GitHubhttps://github.com//issues/130#issuecomment-22814816
.

huragok added a commit to huragok/STA242HW4 that referenced this issue May 18, 2015
Remeber roxygen2 NAMESPACE editing is not compatible with Rstydui project+Rcpp as per
r-lib/roxygen2#130 (comment)
hadley added a commit that referenced this issue Sep 20, 2022
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants