Reputation: 11377
OK, so I have created an R package foo with function Rcpp.package.skeleton
. I have also compiled the Hello World C++ file with
R CMD SHLIB foo/src/rcpp_hello_world.cpp
However, when I call rcpp_hello_world
I get an error:
> source("foo/R/rcpp_hello_world.R")
> rcpp_hello_world()
Error in .Call("rcpp_hello_world", PACKAGE = "foo") :
"rcpp_hello_world" not available for .Call() for package "foo"
Any clues?
Upvotes: 1
Views: 1700
Reputation: 8126
To run the "hello world" example, do the following:
Start R and install the Rcpp package by:
install.packages('Rcpp')
Generate Rcpp template, in R:
Rcpp.package.skeleton("mypackage")
Next, create an archive for the package:
R CMD build mypackage
Exit R. You should see a folder "mypackage" generated. Type the following to check the package:
R CMD check mypackage
Now, you will see an archive mypackage_1.0.tar.gz
. Install it:
R CMD INSTALL mypackage_1.0.tar.gz
Let's run the package in R. Start R and do the following:
library('mypackage')
rcpp_hello_world() # Try the C++ function generated in the template
[[1]] [1] "foo" "bar"
[[2]] [1] 0 1
Upvotes: 1
Reputation: 368519
"Package skeleton" implies that you are supposed to follow the creation of a (simple, skeleton) package with (optionally) building the package (into a tar.gz) as well as installing it.
Once installed you can load it and then you can in fact execute the new function.
Alternatively, you can work on the fly via Rcpp Attributes and/or the inline package.
Upvotes: 6