简体   繁体   中英

Interaction between C and R

I have naive questions to ask:

1) When I want to call C in R, I have to write some C code. But sometimes I have to call a function which is written in R by myself, can I call that function in the C function?

2) If 1) is feasible, then if I use a function written in R repeatedly for 1000 times for a loop, will this speed up by using C to call this function to do the loop?

Well put question. A quick take:

  1. Yes you can. It is (as so many things) possible yet a little tedious with the C-based API that R offers -- but (in our opinion at least) much easier with the C++ layer we put on top via Rcpp

  2. That is the critical point. If the R code is the bottleneck, it remains the bottleneck when you call it from C or C++ as it does not matter where it is called from . What matters is its relative speed.

The rcpp-devel list (links are on Rcpp page ) has a lot of related discussions; you can also find a lot here on SO under the [rcpp] tag.

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