2011-02-18 91 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\")");