[Rcpp-devel] How to use https://github.com/jjallaire/rcpp-gallery/blob/gh-pages/src/2013-01-05-r-function-from-c++.cpp?

Peng Yu pengyu.ut at gmail.com
Fri May 24 06:46:13 CEST 2013


Hi Xiao,

Where is sourceCpp? I don't see it in my Rcpp.

~/dvcs_src/rcpp-gallery/src$ R
> library(Rcpp)
> sourceCpp
Error: object 'sourceCpp' not found
> library(Rcpp)
> sessionInfo()
R version 3.0.0 (2013-04-03)
Platform: x86_64-apple-darwin10.8.0 (64-bit)

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

other attached packages:
[1] Rcpp_0.9.13

On Thu, May 23, 2013 at 11:27 PM, Xiao He <praguewatermelon at gmail.com> wrote:
> If you compile it from within R using sourceCpp("cpp_file_name.cpp "). Or if
> you use the package inline, you can do the following inside R.
>
> cppFunction('
>       NumericVector callFunction(NumericVector x, Function f) {
>            NumericVector res = f(x);
>            return res;
>      }'
>  )
>
> Both methods let you directly call the function callFunction(x, f) (without
> having to use .Call())
>
> callFunction(rnorm(30), sum)
>
>
>
>
>
> On Thu, May 23, 2013 at 9:14 PM, Peng Yu <pengyu.ut at gmail.com> wrote:
>>
>> Hi,
>>
>> I'm able to compile 2013-01-05-r-function-from-c++.cpp to the .so
>> file. But I'm not able to call "callFunction" in R does anybody know
>> what the correct way is to call R functions in C++? Thanks.
>>
>> > dyn.load('2013-01-05-r-function-from-c++.so')
>> > x <- rnorm(1e5)
>> > .Call('callFunction', x, fivenum)
>> Error in .Call("callFunction", x, fivenum) :
>>   C symbol name "callFunction" not in load table
>> > callFunction(x, fivenum)
>> Error: could not find function "callFunction"
>>
>> --
>> Regards,
>> Peng
>> _______________________________________________
>> Rcpp-devel mailing list
>> Rcpp-devel at lists.r-forge.r-project.org
>> https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
>
>



-- 
Regards,
Peng


More information about the Rcpp-devel mailing list