运行 通过 RInside 时 abline 出错

error in abline when run via RInside

我 运行 在使用 RInside 与控制台时遇到问题。这是 ubuntu 14.04 上的所有 运行,使用通过 apt-get 从 CRAN 安装的 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 发生。

有什么想法吗?

对我来说没有任何问题。 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() 打开设备文件 ...