2011-02-18 93 views
2

我想使用RInside编译R代码。但是在使用函数read.csv时出现错误。下面的代码片段给出:编译RInside代码时出错

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 
+0

我认为你在c中没有背景。如果你在查看控制台之前,你会意识到“gedit”(文本编辑器)试图对着色单词说些什么。 – 2011-02-18 08:57:28

+0

Rember认为这不是R代码的编译,只是将它嵌入到C++代码中 - 这不会更快或者类似的东西。 – mbq 2011-02-18 08:58:18

回答

1

你有双引号"双引号字符串中

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

所以,刚刚逃生它带有反斜杠\,然后重试。

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