简体   繁体   中英

How to call a C++ function from R script inside a package (RCpp)?

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!

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM