首页 \ 问答 \ 通过RInside运行时的abline错误(error in abline when run via RInside)

通过RInside运行时的abline错误(error in abline when run via RInside)

我使用RInside和控制台遇到了问题。 这一切都在ubuntu 14.04上运行,使用来自CRAN的apt-get安装的R 3.2.4。 这是c ++和R代码:

#include <RInside.h>                            // for the embedded R via RInside

int main(int argc, char *argv[]) {

    RInside R(argc, argv);                      // create an embedded R instance
    R.parseEval("source('abline.R')");
}

abline.R

bp <- data.frame(
  age = c(28, 23, 52, 42, 27, 29, 43, 34, 40, 28),
  systolic = c(70, 68, 90, 75, 68, 80, 78, 70, 80, 72))
str(bp)
attach(bp)

bp.lm <- lm(systolic ~ age)

plot(age, systolic)
abline(bp.lm)
lines(lowess(age, systolic, f=0.75), lty=2)

R代码在控制台上工作正常,但在程序运行时出错。

mlilback@rc2x:/tmp/abtest$ ./abtest 
'data.frame':   10 obs. of  2 variables:
 $ age     : num  28 23 52 42 27 29 43 34 40 28
 $ systolic: num  70 68 90 75 68 80 78 70 80 72
Error in if (noInt) { : argument is of length zero
terminate called after throwing an instance of 'std::runtime_error'
  what():  Error evaluating: source('abline.R')
Aborted (core dumped)

if (noInt) {来自abline的来源(我的R版本中的第18行)。 我完全难过为什么这只发生在RInside。

有任何想法吗?


I'm running into a problem using RInside vs the console. This is all run on ubuntu 14.04 using R 3.2.4 installed via apt-get from CRAN. Here is the c++ and R code:

#include <RInside.h>                            // for the embedded R via RInside

int main(int argc, char *argv[]) {

    RInside R(argc, argv);                      // create an embedded R instance
    R.parseEval("source('abline.R')");
}

abline.R

bp <- data.frame(
  age = c(28, 23, 52, 42, 27, 29, 43, 34, 40, 28),
  systolic = c(70, 68, 90, 75, 68, 80, 78, 70, 80, 72))
str(bp)
attach(bp)

bp.lm <- lm(systolic ~ age)

plot(age, systolic)
abline(bp.lm)
lines(lowess(age, systolic, f=0.75), lty=2)

The R code works fine from the console, but errors when the program is run.

mlilback@rc2x:/tmp/abtest$ ./abtest 
'data.frame':   10 obs. of  2 variables:
 $ age     : num  28 23 52 42 27 29 43 34 40 28
 $ systolic: num  70 68 90 75 68 80 78 70 80 72
Error in if (noInt) { : argument is of length zero
terminate called after throwing an instance of 'std::runtime_error'
  what():  Error evaluating: source('abline.R')
Aborted (core dumped)

The if (noInt) { is from the source of abline (line 18 in my version of R). I'm completely stumped as to why this only happens via RInside.

Any ideas?


原文:https://stackoverflow.com/questions/38748245
更新时间:2022-01-13 18:01

最满意答案

适合我,没有任何问题。 Ubuntu 16.04。 用完示例目录以免费获取基于GNUmakefile的构建:

~/git/rinside/inst/examples/standard(master)$ vi soquestion.cpp
~/git/rinside/inst/examples/standard(master)$ make soquestion
ccache g++ -I/usr/share/R/include -I/usr/local/lib/R/site-library/Rcpp/include \
     -I/usr/local/lib/R/site-library/RInside/include -g -O3 -Wall -pipe \
     -Wno-unused -Wall    soquestion.cpp  -Wl,--export-dynamic -fopenmp \
     -L/usr/lib/R/lib -lR -lpcre -llzma -lbz2 -lz -lrt -ldl -lm  -lblas -llapack  \
     -L/usr/local/lib/R/site-library/RInside/lib -lRInside \
     -Wl,-rpath,/usr/local/lib/R/site-library/RInside/lib -o soquestion
~/git/rinside/inst/examples/standard(master)$ vi abline.R
~/git/rinside/inst/examples/standard(master)$ ./soquestion 
'data.frame':   10 obs. of  2 variables:
 $ age     : num  28 23 52 42 27 29 43 34 40 28
 $ systolic: num  70 68 90 75 68 80 78 70 80 72
~/git/rinside/inst/examples/standard(master)$ 

我只是复制粘贴你的两个文件。 也:

~/git/rinside/inst/examples/standard(master)$ ls -1tr | tail -4
soquestion.cpp
soquestion
abline.R
Rplots.pdf
~/git/rinside/inst/examples/standard(master)$ 

您可能想通过pdf()png()打开设备文件...


Works for me without any issues. Ubuntu 16.04. Running out of the examples directory to get the GNUmakefile-based build for free:

~/git/rinside/inst/examples/standard(master)$ vi soquestion.cpp
~/git/rinside/inst/examples/standard(master)$ make soquestion
ccache g++ -I/usr/share/R/include -I/usr/local/lib/R/site-library/Rcpp/include \
     -I/usr/local/lib/R/site-library/RInside/include -g -O3 -Wall -pipe \
     -Wno-unused -Wall    soquestion.cpp  -Wl,--export-dynamic -fopenmp \
     -L/usr/lib/R/lib -lR -lpcre -llzma -lbz2 -lz -lrt -ldl -lm  -lblas -llapack  \
     -L/usr/local/lib/R/site-library/RInside/lib -lRInside \
     -Wl,-rpath,/usr/local/lib/R/site-library/RInside/lib -o soquestion
~/git/rinside/inst/examples/standard(master)$ vi abline.R
~/git/rinside/inst/examples/standard(master)$ ./soquestion 
'data.frame':   10 obs. of  2 variables:
 $ age     : num  28 23 52 42 27 29 43 34 40 28
 $ systolic: num  70 68 90 75 68 80 78 70 80 72
~/git/rinside/inst/examples/standard(master)$ 

I literally just copied an pasted your two files. Also:

~/git/rinside/inst/examples/standard(master)$ ls -1tr | tail -4
soquestion.cpp
soquestion
abline.R
Rplots.pdf
~/git/rinside/inst/examples/standard(master)$ 

You probably want to open a device file via pdf() or png() ...

相关问答

更多
  • 它失败是因为您在C:\Program Files\R安装了R,即使Windows上的R的FAQ告诉您不要在带空格的路径中安装R. 请参阅“问题2.2:如何为Windows安装R”: 如果您希望能够从源构建包,我们建议您选择不包含空格的安装路径。 Rcpp / RInside文档重复了该建议。 不要在带空格的路径中安装R. 如果必须,您必须修复Makefile以避免路径扩展中断。 It fails because you installed R in C:\Program Files\R even thoug ...
  • 试试这个: plt.plot(Boston.lstat, fit_1.fittedvalues, 'r') Try this: plt.plot(Boston.lstat, fit_1.fittedvalues, 'r')
  • 您可以向aes添加color或linetype ,然后使用scale_color_xxx或scale_linetype_xxx微调图例。 以下是使用economics数据集的示例 library(tidyverse) df <- economics %>% select(date, psavert, uempmed) %>% gather(key = "variable", value = "value", -date) ggplot(df, aes(x = date, y = value)) ...
  • 我不确定你失去了什么,但基本的想法是这样说: 转到目录。 以防万一。 make (这是make all )或只有一个。 这仍然有效 - 我自己使用Debian / Ubuntu。 这里是做make rinside_sample0来证明这一点,然后运行它: edd@rob:~$ cd git/rinside/inst/examples/standard/ edd@rob:~/git/rinside/inst/examples/standard$ make -f GNUmakefile clean rm -vf ...
  • 适合我,没有任何问题。 Ubuntu 16.04。 用完示例目录以免费获取基于GNUmakefile的构建: ~/git/rinside/inst/examples/standard(master)$ vi soquestion.cpp ~/git/rinside/inst/examples/standard(master)$ make soquestion ccache g++ -I/usr/share/R/include -I/usr/local/lib/R/site-library/Rcpp/incl ...
  • 以下将格子xyplot打印到png。 这是一个最小的例子,作为rinside_sample11.cpp的变体。 #include // for the embedded R via RInside #include int main(int argc, char *argv[]) { // create an embedded R instance RInside R(argc, argv); ...
  • 您得到的错误是因为Rcpp.h包含在RcppArmadillo.h之前, Rcpp.h包含在RInside.h 。 对于RcppArmadillo给你的魔力,需要在Rcpp.h之前加载文件Rcpp.h 。 所以我建议你这样做: #include #include The error you get is because Rcpp.h is included before RcppArmadillo.h, Rcpp.h is included by ...
  • 尝试将以下内容添加到g ++构建的末尾 -lRInside -lRcpp 这样你就拥有了 g++ rinsidetest.cpp -I /usr/lib64/R/library/RInside/include/ -I /usr/lib64/R/library/Rcpp/include/ -I /usr/lib64/R/include/ -L /usr/lib64/R/library/RInside/libs/ -L /usr/lib64/R/library/Rcpp/libs/ -lRInside -l ...
  • 当你使用RInside时 ,你会创建一个独立的C ++程序 - 它恰好与R链接,以便R嵌入。 因此, valgrind的使用与另一个C ++程序没有什么不同。 您希望valgrind分析的所有代码可能必须使用正确的设置进行重建(请参阅在Valgrind站点上准备您的程序 ),如果您希望在这些组件上也使用Valgrind输出,则还包括R和RInside 。 When you use RInside, you create a standalone C++ program---which happens to ...
  • 我们可以使用if/else条件 CBT <- function(g,r,n,tl){ curve(dt(x,n),-5,6,col="red") if(tl==2){ abline(v=c(-2,2), col="green") } else { abline(v = 2, col="green") } } CBT(.4,.05,20,2) 如果我们需要条件,即'tl'表示1,2和其他情况 CBT <- function(g,r,n,tl){ curve(dt(x,n),-5,6,col ...

相关文章

更多

最新问答

更多
  • Google会更新重定向网址吗?(Does Google update redirect URLs? [closed])
  • 如何将js-variable从.js文件传递给Electron中的.html页面?(How to pass js-variable from .js file to .html page in Electron?)
  • matlab中的数据处理gui - 从文件和文本框中读取并传递给函数(data handling in matlab gui - reading from file and textbox and pass to function)
  • SVG矩形的笔划宽度在顶部/左侧被切除。(SVG rectangle's stroke widths are cut off on top/left. How do I fix this?)
  • BOOST_CHECK中的错误?(Bug in BOOST_CHECK?)
  • 使用ActiveDocument时记录替换量(Recording the amount of replacements when using ActiveDocument)
  • 将php数组转换为javascript数组(convert php array to a javascript array)
  • 在斯威夫特干邑国际象棋引擎与iOS项目集成(Stockfish Chess Engine Integration with iOS project in Swift)
  • C# - 增加一个双倍值(1.212E + 25)(C# - Incrementing a double value (1.212E+25))
  • 取消asynctask的最佳方法(Best way to cancel asynctask)
  • 文件转换问题的最佳方法(Best approach to File Conversion problems)
  • 从分组数据中选择第一行和最后一行(Select first and last row from grouped data)
  • 哪些元素可以禁用?(What elements can ng-disabled be applied to?)
  • ASP.NET GridView在回发时为空(ASP.NET GridView empty on postback)
  • lua环境和模块(lua environments and modules)
  • 如何将小切片复制到更大切片的末尾(How to copy a small slice to the end of a bigger slice)
  • IIS7 URL重写模块替换(IIS7 URL Rewriting Module Replace)
  • IE和Google Chrome中的多表单提交(Multi-forms submission in IE and Google chrome)
  • Symfony2:如何在控制器中检索UserChecker?(Symfony2: How to retrieve the UserChecker in a controller?)
  • 循环通过数组和删除项目,而不破坏循环(Looping through array and removing items, without breaking for loop)
  • 如何动态更改YouTube播放器的选项(How to dynamically change YouTube player's options)
  • Laravel使用以点开头的文件处理存储磁盘(Laravel working through storage disk with files starting with dot)
  • 在挂架中使用重定向时出错(Error using redirect in pylons)
  • 替换netCDF文件中的变量(Replacing a variable inside a netCDF file)
  • 让swable中的非可变数组(let Non-mutable array in swift)
  • 春季安全缺省登录页面代码位于何处?(Where is spring security default login page code located?)
  • Unix - 并排打印公共线(Unix - Print Common Lines side by side)
  • 验证TimeSpan(Validating TimeSpan)
  • 如果还有一个具有返回值的重载版本,如何正确调用非返回值Swift函数?(How do I properly call a non-return-value Swift function when it also has an overloading version that has returned value?)
  • Perl:比较两个文件并打印匹配和不匹配的数据(Perl: Comparing two files and printing data that match and don't match)