编译 RInside 代码时出错

发布于 2024-10-18 12:26:02 字数 967 浏览 4 评论 0原文

我想使用 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  

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  

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一袭白衣梦中忆 2024-10-25 12:26:02

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

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

因此,只需用反斜杠 \ 转义它,然后重试。

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

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\")"); 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文