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

Consider removing the rcpp_ prefix from C++ functions #12

Open
huisaddison opened this issue Feb 15, 2023 · 0 comments
Open

Consider removing the rcpp_ prefix from C++ functions #12

huisaddison opened this issue Feb 15, 2023 · 0 comments

Comments

@huisaddison
Copy link
Contributor

Motivation: the rcpp_ prefix for C++ functions is meant to distinguish the "C++ functions" which are meant to be internal to the dspline package implementation from the "R functions" which are meant to be exposed to the end-user.

Ideally, though, I think it's cleaner to drop the rcpp_ prefix in C++.

  1. It makes the code less cumbersome when called within C++ code from other packages (which can use C++ functions in dspline via LinkingTo).
  2. As discussed in Minimize dependence on functions/behaviors provided by Rcpp #11 , much of the code can be [re]written without explicit dependence on Rcpp, and hence the rcpp_ prefix is a misnomer. If we "need" a prefix, it should at least just be cpp_. But that just feels redundant when used within C++ code.

So what can we do to avoid "name conflicts" between the C++ functions and R functions when the former are exported to R? Technically, Rcpp already provides a solution via the Rcpp::exports('function_name') attribute. See the documentation here. This allows one to "specify an alternate for the generated R function"; by default, if no alternate is given, then the C++ function's name is used.

The problem, however, is that this alternate name is also used for the C++ function when it is "exported" into a header file to become available for other R packages via LinkingTo, using the Rcpp::interfaces attribute. Although it is not explicitly stated in the documentation, I have found this to be the case by playing with the code.

So, for example, I could have a function called n_mat in the dspline C++ code, which is exported to R as rcpp_n_mat. And I would want it to be available in trendfilter C++ code as n_mat, but instead it is available as rcpp_n_mat.

I don't have a clean solution for this right now; otherwise I would have just done it and PR'd. The only "complete" solution which achieves what I describe above is to implement "pure C++" functions which export a C++ interface to other packages, and then within dspline create wrapper rcpp_ functions to be exported to R, which call the pure C++ functions. But that seems awfully cumbersome...

It might also be worth posting on StackOverflow to see if other users have dealt with this interaction between the export and interfaces attributes in Rcpp before. For now, I'm leaving the prefixes as is, and we can revisit this later on.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant