这是我的剧本
library(Rcpp)
library(inline)
myroot2 <- rcpp(signature(xs="numeric"), body='double x=as<double>(xs); return wrap(::sqrt(x));')
print(myroot2(100))
如果我从R中获取此脚本,那么它运行得很好
>source('test.R')
Attaching package: ‘inline’
The following object is masked from ‘package:Rcpp’:
registerPlugin
[1] 10
以批处理模式
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
该如何解决?
答案 0 :(得分:1)
signature
函数位于methods
中,显然默认情况下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
。