编译RInside代码时出错

时间:2011-02-18 08:24:43

标签: c++ r rcpp rinside

我想使用RInside编译R代码。但是我在使用函数read.csv时遇到错误。代码段如下:

include "RInside.h"
include <iomanip>  
include <iostream>  
include <fstream>  
include <string>    
include <vector>   
include <sstream>    
using namespace std;

int main(int argc,char*argv[])
{   
 RInside R(argc,argv);  
 SEXP ans;  
 R.parseEvalQ("library(plotrix)");  
 R.parseEvalQ("fileContents<-read.csv("/home/nibha/manoj/test.csv")");  
 R.parseEvalQ("nr <-nrow (filecontents)");  
 R.parseEvalQ("nc <-ncol (filecontents)");  
}  

我收到的错误如下:

: In function ‘int main(int, char**)’:  
prog3.cpp:14: error: ‘home’ was not declared in this scope  
prog3.cpp:14: error: ‘nibha’ was not declared in this scope  
prog3.cpp:14: error: ‘manoj’ was not declared in this scope  
prog3.cpp:14: error: ‘test’ was not declared in this scope  
prog3.cpp:20: error: ‘myfile’ was not declared in this scope  

1 个答案:

答案 0 :(得分:1)

您在双引号字符串

中有双引号"
R.parseEvalQ("fileContents<-read.csv("/home/nibha/manoj/test.csv")"); 

所以,只需用反斜杠\转义它,然后再试一次。

R.parseEvalQ("fileContents<-read.csv(\"/home/nibha/manoj/test.csv\")");