2

I am trying to write an R package with Rcpp. Everything works well except for a warning emitted by R CMD check my_package.

Status: 1 WARNING
checking for missing documentation entries ... WARNING
Undocumented code objects:
  ‘shiny_function’
All user-level objects in a package should have documentation entries.

Here shiny_function is implemented in C++ and exported with an Rcpp attribute

// [[Rcpp::export]]
int shiny_function(int arg) {
  return arg;
}

The problem is I want to "rename" it to shiny.function when exporting to R, so in R/shiny_function.R I have

shiny.function <- function(arg) {
  .Call("_my_package_shiny_function", arg)
}

After getting this warning, I modified NAMESPACE to have exportPattern("^[^_]+") as an attempt to avoid exporting functions with underlines in their name, but the warning persists.

How do I "rename" an Rcpp function written in C++?

nalzok
  • 14,965
  • 21
  • 72
  • 139
  • Do you have some roxygen2 code before `shiny.function` ? – Stéphane Laurent Mar 29 '19 at 15:18
  • @StéphaneLaurent No, I don't. I'm writing a little package that exports only 2 functions, so I'd like to keep things simple and easy. – nalzok Mar 29 '19 at 15:20
  • Possible duplicate of [R package, hidden Rcpp function](https://stackoverflow.com/questions/46039132/r-package-hidden-rcpp-function) – coatless Mar 29 '19 at 15:21
  • 2
    How about `// [[Rcpp::export(shiny.function)]]`? – Ralf Stubner Mar 29 '19 at 16:04
  • @RalfStubner Now I'm getting `Found no calls to: ‘R_registerRoutines’, ‘R_useDynamicSymbols’`. Do I need to make any change to other places? – nalzok Mar 30 '19 at 01:12
  • 1
    Sorry, not enough context. Calls to these functions are generated with `Rcpp::compileAtributes` and can be found in `RcppExports.cpp`. – Ralf Stubner Mar 30 '19 at 07:38

1 Answers1

5

This is pretty elementary: when you add a tag [[Rcpp::export]] you get exactly what you asked for: an exported function. And exported means globally visible.

If you don't want that, just removed the tag. You still have a function you can address via .Call() the usual way, and you can do whatever you please at the R layer including renaming, argument control and validation and more.

If you look closely at the (copious, I am aware) documentation you will see in the Rcpp Attributes vignette that you can also control what is exported and to whom (i.e. you can have functions visible to C++ layers).

Dirk Eddelbuettel
  • 360,940
  • 56
  • 644
  • 725
  • Doesn't seem to work. Now I'm getting `Found no calls to: ‘R_registerRoutines’, ‘R_useDynamicSymbols’`, and `It is good practice to register native routines and to disable symbol search.` – nalzok Mar 29 '19 at 15:42
  • Well you chose to do things by hand and now you have to -- see the fine manual _Writing R Extensions_ for how. Or, if you want to be clever, just pust the export tag back, have it autogenerated _and then just copy it to another file_ before turning the tag off. In short, "registration != export". – Dirk Eddelbuettel Mar 29 '19 at 15:47
  • *sigh* I'm not using roxygen2 for the time being (but I guess I'll have to). What do you mean by "have it autogenerated and then just copy it to another file before turning the tag off"? Are you instructing me to copy the autogenerated `RcppExports.cpp` to `RcppExports.cpp.bak`, before deleting the `// [[Rcpp::export]]` line? – nalzok Mar 29 '19 at 15:53
  • 1
    Maybe you need to slow down a little and read more. I never mentioned `roxygen2`, either implictly or explicitly. It is not part of an Rcpp toolchain and not required (though many people use it for some tasks; if you check StackOverflow questions you will also see that it confuses a lot of people too as it also touches some files I mentioned -- and that is the reason I don't recommend it for those tasks). – Dirk Eddelbuettel Mar 29 '19 at 16:03
  • Thanks for your suggestions, and I’m heading to the documents. Please allow me to complain a bit, though. Honestly, *Writing R Extensions* is just too comprehensive for my purpose, i.e. wrapping a few demonstrative functions into a package. Just saying, it would be nice to have something between the Rcpp vignette and WRE in detailedness. Sometimes an outline of just-right granularity can be very helpful to users who are in a hurry. – nalzok Mar 29 '19 at 16:17
  • 4
    ==:-) I hear you but I also have been reading, and re-reading, and re-reading _Writing R Extensions_ since the 1990s myself. It is what it is. And until _someone_ sits down and writes better docs it won't improve. Maybe your calling is to write those docs... – Dirk Eddelbuettel Mar 29 '19 at 16:28