You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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++.
It makes the code less cumbersome when called within C++ code from other packages (which can use C++ functions in dspline via LinkingTo).
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.
The text was updated successfully, but these errors were encountered:
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++.LinkingTo
).Rcpp
#11 , much of the code can be [re]written without explicit dependence on Rcpp, and hence thercpp_
prefix is a misnomer. If we "need" a prefix, it should at least just becpp_
. 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 theRcpp::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 asrcpp_n_mat
. And I would want it to be available in trendfilter C++ code asn_mat
, but instead it is available asrcpp_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
andinterfaces
attributes in Rcpp before. For now, I'm leaving the prefixes as is, and we can revisit this later on.The text was updated successfully, but these errors were encountered: