Error while compiling RInside code

465 views Asked by At

I want to compile a R code using RInside. But I am getting errors while using the function read.csv. The code snippet is given below:

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)");  
}  

I am getting the errors as follows:

: 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

There are 1 answers

1
YOU On

You have double quote " inside double-quoted string

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

So, just escape it with backslash \, and try again.

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