通过RInside运行时的abline错误

时间:2016-08-03 15:47:19

标签: c++ r rinside

我遇到了使用RInside与控制台的问题。这一切都在ubuntu 14.04上运行,使用从CRAN通过apt-get安装的R 3.2.4。这是c ++和R代码:

#include <RInside.h>                            // for the embedded R via RInside

int main(int argc, char *argv[]) {

    RInside R(argc, argv);                      // create an embedded R instance
    R.parseEval("source('abline.R')");
}

abline.R

bp <- data.frame(
  age = c(28, 23, 52, 42, 27, 29, 43, 34, 40, 28),
  systolic = c(70, 68, 90, 75, 68, 80, 78, 70, 80, 72))
str(bp)
attach(bp)

bp.lm <- lm(systolic ~ age)

plot(age, systolic)
abline(bp.lm)
lines(lowess(age, systolic, f=0.75), lty=2)

R代码在控制台上工作正常,但在程序运行时出错。

mlilback@rc2x:/tmp/abtest$ ./abtest 
'data.frame':   10 obs. of  2 variables:
 $ age     : num  28 23 52 42 27 29 43 34 40 28
 $ systolic: num  70 68 90 75 68 80 78 70 80 72
Error in if (noInt) { : argument is of length zero
terminate called after throwing an instance of 'std::runtime_error'
  what():  Error evaluating: source('abline.R')
Aborted (core dumped)

if (noInt) {来自abline的来源(我的R版本中的第18行)。我完全难过为什么这只发生在RInside。

有什么想法吗?

1 个答案:

答案 0 :(得分:1)

为我工作没有任何问题。 Ubuntu 16.04。用完示例目录以免费获得基于GNUmakefile的构建:

~/git/rinside/inst/examples/standard(master)$ vi soquestion.cpp
~/git/rinside/inst/examples/standard(master)$ make soquestion
ccache g++ -I/usr/share/R/include -I/usr/local/lib/R/site-library/Rcpp/include \
     -I/usr/local/lib/R/site-library/RInside/include -g -O3 -Wall -pipe \
     -Wno-unused -Wall    soquestion.cpp  -Wl,--export-dynamic -fopenmp \
     -L/usr/lib/R/lib -lR -lpcre -llzma -lbz2 -lz -lrt -ldl -lm  -lblas -llapack  \
     -L/usr/local/lib/R/site-library/RInside/lib -lRInside \
     -Wl,-rpath,/usr/local/lib/R/site-library/RInside/lib -o soquestion
~/git/rinside/inst/examples/standard(master)$ vi abline.R
~/git/rinside/inst/examples/standard(master)$ ./soquestion 
'data.frame':   10 obs. of  2 variables:
 $ age     : num  28 23 52 42 27 29 43 34 40 28
 $ systolic: num  70 68 90 75 68 80 78 70 80 72
~/git/rinside/inst/examples/standard(master)$ 

我只是复制了粘贴你的两个文件。也:

~/git/rinside/inst/examples/standard(master)$ ls -1tr | tail -4
soquestion.cpp
soquestion
abline.R
Rplots.pdf
~/git/rinside/inst/examples/standard(master)$ 

您可能希望通过pdf()png() ...

打开设备文件