在R中运行,但不在Rscript中运行

在R中运行,但不在Rscript中运行,r,inline,rcpp,R,Inline,Rcpp,这是我的剧本 library(Rcpp) library(inline) myroot2 <- rcpp(signature(xs="numeric"), body='double x=as<double>(xs); return wrap(::sqrt(x));') print(myroot2(100)) 在批处理模式下 Rscript --verbose test.R running '/usr/local/share/bcbio/anaconda/lib/R/bin/

这是我的剧本

library(Rcpp)
library(inline)

myroot2 <- rcpp(signature(xs="numeric"), body='double x=as<double>(xs); return wrap(::sqrt(x));')
print(myroot2(100))
在批处理模式下

Rscript --verbose test.R
running
'/usr/local/share/bcbio/anaconda/lib/R/bin/R --slave --no-restore -- 
file=test.R'


Attaching package: ‘inline’

The following object is masked from ‘package:Rcpp’:

registerPlugin
Error in signature(xs = "numeric") : could not find function 
"signature"
Calls: rcpp -> cxxfunction
Execution halted
如何修复此问题?

签名函数位于方法中,显然默认情况下没有使用Rscript加载。试试这个:

library(Rcpp)
library(inline)

myroot2 <- rcpp(methods::signature(xs="numeric"), body='double x=as<double>(xs); return wrap(::sqrt(x));')
print(myroot2(100))

其中唯一的更改是使用methods::signature。

它加载在R版本3.5.0及更高版本中。那个改变早就过期了。@DirkEddelbuettel,很好地抓住了这个陷阱,我还没看到。哦,关于Rscript的每一个问题都是关于这个:
library(Rcpp)
library(inline)

myroot2 <- rcpp(methods::signature(xs="numeric"), body='double x=as<double>(xs); return wrap(::sqrt(x));')
print(myroot2(100))