Renaming and Hiding an Exported Rcpp function in an R Package

后端 未结 2 958
我在风中等你
我在风中等你 2020-12-06 12:16

Writing an R package, I have a R function that calls a specific Rcpp function. The Rcpp function just serves as a helper function and I do not want to creat a .Rd file for i

2条回答
  •  攒了一身酷
    2020-12-06 12:47

    There are two aspects here:

    1. Have the C++ function callable from R. You need the // [[Rcpp::export]] tag for that, and it will create an R interface.

    2. Have that R/C++ interface function 'visible' to clients of the package. That is different and controlled by NAMESPACE. Just do not list it there, only list your other function. You can still call it from the outside by using the colons: yourpackage:::yourCppFunction().

    That way your C++ code is callable (per 1.) and does not need an Rd file (per 2. as it is not exported.) Only your visible R wrapper needs an man page entry.

    For one worked example see this C++ file in the anytime package which is not in the NAMESPACE file, hence has no help page, yet is still callable to test code.

提交回复
热议问题