Suppose I have compiled a code with two functions f1
and f2
using Rcpp::sourceCpp('myPath/myCode.cpp')
and I located the sourceCpp_123123.dll
that was created.
Now suppose I have two different batch files on Windows 7, both of which run RScript -e "source('myRCode1.r')"
and RScript -e "source('myRCode2.r')"
respectively. I want my two functions f1
and f2
to be available with each run of RScript
.
I can certainly put in my code myRCode1.r
and myRCode2.r
to do Rcpp::sourceCpp('myPath/myCode.cpp')
before rest of the code is run. Another alternative is to convert my two functions f1
and f2
into a package which is a little more involved process.
Is there any easy way to simply load the sourceCpp_123123.dll
within myRCode1.r
and myRCode2.r
?
I tried dyn.load("myDllPath\sourceCpp_123123.dll")
with various permutations and combinations of now=TRUE
, local=TRUE
, now=FALSE
, local=FALSE
, but none of the options loaded the two functions.
However, when I tried getLoadedDLLs
, I see that sourceCpp_123123.dll
has been loaded!
As I commented earlier, this is where you want to use a package.
Or if you are one of those people opposed to packages on whichever grounds (none of which typically convince an experienced R user / programmer who will almost always advocate use of package), then you could cheat and just combine your two files into one.
Which would couple the two function sets. And you may already know that you can mix C++ and R code in one file as we do all the time over at the Rcpp Gallery...