我试图在我的win7 64位系统上嵌入RInside我的应用程序,但是当我初始化一个RInside时:
Rin = new RInside(argc, argv);
Run Code Online (Sandbox Code Playgroud)
出现以下消息:
loadNamespace(name)出错:没有名为'Rcpp'的包
此错误仅发生在Windows上.
我正在尝试设置RInside工作,我们被迫使用Windows环境.
我安装了RTools并从CRAN下载了一个RInside二进制文件.
我的R安装位于c:\ R\R-2.12.2,因此带有空格的文件夹没有问题.
我在R中安装了Rcpp和RInside软件包.
我执行以下makefile Makefile.win包含在下载的RInside二进制文件中
## -*- mode: makefile; tab-width: 8; -*-
##
## Simple Makefile
##
## TODO:
## proper configure for non-Debian file locations, [ Done ]
## allow RHOME to be set for non-default R etc
## comment this out if you need a different version of R,
## and set set R_HOME accordingly as an environment variable …
Run Code Online (Sandbox Code Playgroud) 是否可以从c ++调用绘图函数?目前,当我尝试这样做时,ubuntu终端会冻结一段时间(可能是创建3d绘图然后旋转整整360度的持续时间)然后解冻,而不会弹出新窗口.这是预期的行为还是我做错了什么?如何使用rinside和rcpp从c ++中运行绘图(R图形)?
日Thnx
-Egon
我试图通过RInside在C++中使用R. 我无法将犰狳矩阵传递给R并返回结果.下面我能够从R库函数返回结果,但是我得到了错误的结果.我正在使用moment包中的skewness函数作为示例,它在R中应该起作用.我检查了来自RInside的示例,我仍然不确定如何使用RcppArmadillo.如何将c ++中的犰狳矩阵正确传递给R?
#include <RInside.h>
#include <RcppArmadillo.h>
using namespace std;
using namespace arma;
int main(int argc, char *argv[]) {
RInside R(argc, argv);
string R_libs = "suppressMessages(library(moments));";
R.parseEvalQ(R_libs);
mat A = randu<mat>(5,5);
R["A"] = A;
string R_skewness = "B <- skewness(A);";
//this fails
mat B = Rcpp::as<mat>(R.parseEval(R_skewness)); //terminate called after throwing an instance of 'Rcpp::not_a_matrix'
//this works but wrong
mat B = Rcpp::as<vec>(R.parseEval(R_skewness)); // returns only 1 number, should be 5 ( 1 for each columnn), same result if i change …
Run Code Online (Sandbox Code Playgroud) 我正在尝试用Rinside编译Rarmadillo示例,我一直在:
In file included from rinside_arma0.cpp:8:0:
/usr/local64/opt/R-2.15.2/lib/R/library/RcppArmadillo/include/RcppArmadillo.h:26:6: error: #error "The file 'Rcpp.h' should not be included. Please correct to include only 'RcppArmadillo.h'."
Run Code Online (Sandbox Code Playgroud)
我用谷歌搜索它,但我一直在获取源代码.有任何想法吗 ?
代码是:
// -*- c-indent-level: 4; c-basic-offset: 4; indent-tabs-mode: nil; -*-
//
// Simple example using Armadillo classes
//
// Copyright (C) 2012 Dirk Eddelbuettel and Romain Francois
#include <RInside.h> // for the embedded R via RInside
#include <RcppArmadillo.h>
int main(int argc, char *argv[]) {
RInside R(argc, argv); // create an embedded R instance
std::string cmd = …
Run Code Online (Sandbox Code Playgroud) 我一直在使用Rcpp和RInside来集成R和C++.我们有一个复杂但设计良好的C++架构,我发现很难从一个函数中访问R.是否可以将R
实例传递给不同的类/函数,以获得更多的OOP设计?如果是,有什么例子吗?
为了详细说明查询,我想说这样的话,
void foo(RInside& R0, int& x0)
{
R0.assign(x0,"totalSum");
}
void foo2(RInside& R0, int& y0)
{
R0.assign(y0,"temp");
R0.parseEvalQ("totalSum = totalSum + temp");
}
int main(int argc, char *argv[])
{
RInside R(int argc, char *argv[]);
int x=10, y = 11;
foo(R,x);
foo2(R,y);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我目前注意到的是每次调用foo,都可能会创建一个新的RInside实例.
谢谢 - 埃贡
我已经成为R用户大约4年了,在过去的两周里,我一直在开发一个简单的函数包来分析一些数据并以适合项目的方式绘制一些图表,我的团队和主管的其他成员都是工作和一些即将到来的.所以他们现在问我是否可以使它成为一个独立于必须知道R的人的可执行文件 - 所以它是一个单独的.exe文件,带有基于文本的菜单或简单的gui.
从冬天开始,我一直在慢慢学习C++,我认为RInside是最好的方法.使用C++生成一个带有R的.exe,用于绘制令人惊叹的绘图和图形,但它将在我的团队可以使用的可执行文件中.我目前已经介绍了C++变量,带有iostream的基本I/O,布尔和控制流,函数,数组,结构和类,重载朋友和引用.我看过Dirk的博客,我重新安装了R到C:\ R \,我安装了CodeBlocks和MinGW,我一直在学习C++.我需要建议我应该采取什么预防措施,以及在继续之前我应该检查/阅读/知道什么,以及可能是一个新的友好的方式来开始涉水和尝试.
谷歌搜索我发现教程或演练的方式与Rcpp不同,人们(例如像Hadley)编写了很棒的wiki或博客文章,我觉得比跳过更多的技术文档容易一些.
所以,现在我已经设法在WindowsXP(VirtualBox)上编译了RInside的hello程序.但是,当我点击它的可执行文件时,我得到一个显示上述错误的对话框.
搜索Google引导我进入这个线程,他们在谈论以下设置.
R:
> Sys.getenv("R_LIBS")
[1] ""
> Sys.getenv("R_LIBS_USER")
[1] "C:\\Documents and Settings\\admin\\My Documents/R/win-library/2.15"
> Sys.getenv("R_HOME")
[1] "C:/R-2.15.1"
> sessionInfo ()
R version 2.15.1 (2012-06-22)
Platform: i386-pc-mingw32/i386 (32-bit)
locale:
[1] LC_COLLATE=English_United States.1252
[2] LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C
[5] LC_TIME=English_United States.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
>
Run Code Online (Sandbox Code Playgroud)
从这里:http://cran.r-project.org/bin/windows/base/rw-FAQ.html#How-do-I-set-environment-variables_003f
环境变量的优先顺序是列出这些选项的顺序,即命令行.然后是继承环境.
路径:
Rcmd_environ:
## from R.sh
R_SHARE_DIR=${R_HOME}/share
R_INCLUDE_DIR=${R_HOME}/include
R_DOC_DIR=${R_HOME}/doc
R_ARCH=
## from Rcmd
R_OSTYPE=windows
TEXINPUTS=.;${TEXINPUTS};${R_SHARE_DIR}/texmf/tex/latex; …
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用RInside在C++中构建一个R应用程序.我想使用代码将图表保存为指定目录中的图像,
png(filename = "filename", width = 600, height = 400)
xyplot(data ~ year | segment, data = dataset, layout = c(1,3),
type = c("l", "p"), ylab = "Y Label", xlab = "X Label",
main = "Title of the Plot")
dev.off()
Run Code Online (Sandbox Code Playgroud)
png
如果直接从R运行,它会在指定目录中创建一个文件.但是使用来自RInside的C++调用,我无法重现相同的结果.(我可以使用C++调用重现所有基础图.仅使用Lattice和ggplots的问题)
我也使用以下代码,
myplot <- xyplot(data ~ year | segment, data = dataset, layout = c(1,3),
type = c("l", "p"), ylab = "Y Label", xlab = "X Label",
main = "Title of the Plot")
trellis.device(device = "png", filename …
Run Code Online (Sandbox Code Playgroud)