r-lib / cpp11

cpp11 helps you to interact with R objects using C++ code.
https://cpp11.r-lib.org/
Other
199 stars 46 forks source link

cpp_register(): use_package by default #230

Closed alyst closed 1 week ago

alyst commented 3 years ago

For some reason the current symbol-based approach didn't work for me (R 4.0.5) resulting in Symbol not found errors for .Call().

There is already support for an alternative .Call(..., PACKAGE='...') approach, I just extended it to cpp_register() function and made it the default.

jimhester commented 3 years ago

Thanks for working on this, but I am confident that the symbols will work regardless of the R version and we use symbols for packages for a reason.

I suspect there is something else going wrong with registration in your package, would it be possible for you to provide a link to it?

alyst commented 3 years ago

@jimhester It could be because I've missed .registration = TRUE in my useDynLib() directive. Now the symbol-based wrappers seem to work.

For this PR I can set the cpp_register(..., use_package = FALSE, ...), so that the cpp11 behavior would not change, but still there would be a more complete support for generating the wrappers that explicitly specify the package.

jimhester commented 3 years ago

Sure we can expose the argument, though in general I don't think most packages would ever need to use it.

Also FWIW if you use usethis::use_cpp11() to setup cpp11 for your package it will add a roxygen annotation to include .registration = TRUE in your namespace directive.

alyst commented 3 years ago

Ok, I've changed to use_package=FALSE.

DavisVaughan commented 1 week ago

I've decided not to do this for now, as symbols work everywhere and are the most useful thing to use