Reputation: 261
I have a cpp file with the function rcpp_hello_world(). I have an R script (also inside the Rcpp package). How do I call the rcpp_hello_world() function from the R script?
I've looked through Dirk's documentation (http://dirk.eddelbuettel.com/code/rcpp/Rcpp-package.pdf) but I don't see a part about calling the cpp function from an R script that's inside the package.
Obviously this is a simple example I'm using to learn how to interact with the two before I apply it to a much larger project.
Thanks!
Upvotes: 0
Views: 951
Reputation: 261
After looking through http://people.math.aau.dk/~sorenh/teaching/2014-Rcpp/misc/Rcpp-workshop.pdf I found that I had seen the answer before but didn't realize it (http://dirk.eddelbuettel.com/code/rcpp/Rcpp-package.pdf).
To call rcpp_hello_world, in test1.R file, in package test the following is the syntax
test1 <- function(){
.Call('test_rcpp_hello_world', PACKAGE = 'test')
}
is the appropriate syntax. Additionally, it works out that the syntax for all functions (exported by Rcpp) can be found in RcppExports.cpp which is autogenerated on compilation.
Upvotes: 1