简体   繁体   English

C和R之间的相互作用

[英]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. 1)当我想在R中调用C时,我必须编写一些C代码。 But sometimes I have to call a function which is written in R by myself, can I call that function in the C function? 但有时我必须自己调用一个用R编写的函数,我可以在C函数中调用该函数吗?

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? 2)如果1)是可行的,那么如果我在循环中重复使用一个写入R的函数1000次,那么通过使用C来调用该函数来进行循环会加速吗?

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 对于R提供的基于C的API来说,它(很多东西)可能有点乏味 - 但是(至少在我们看来)使用我们通过Rcpp提供的C ++层更容易

  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 . 如果R代码是瓶颈,那么当你从C或C ++调用它时它仍然是瓶颈,因为它从哪里调用无关紧要 What matters is its relative speed. 重要的是它的相对速度。

The rcpp-devel list (links are on Rcpp page ) has a lot of related discussions; rcpp-devel列表(链接在Rcpp页面上 )有很多相关的讨论; you can also find a lot here on SO under the [rcpp] tag. 你也可以在[rcpp]标签下找到很多。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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