gpt4 book ai didi

c++ - 从 C++ 程序调用 R(在 Linux 中)

转载 作者:太空宇宙 更新时间:2023-11-04 05:21:44 26 4
gpt4 key购买 nike

我在这里做错了什么?当我像这样直接调用Rscript

/home/vagrant/bin/Rscript -e "x <- 2; x+1"

我得到这个输出

[1] 3

当我使用 execl() 从 C++ 程序调用 Rscript 时,出现错误。

调用Rscript的代码片段如下

void callR_dummy(int i) {
int errval = execl("/home/vagrant/bin/Rscript", "-e", "x <- 2; x+1", (char*) NULL);
int err = errno;
cout <<"callR " << i << " : errno = " << err << endl;
}

我明白

Fatal error: cannot open file 'x <- 2; x+1': No such file or directory

在有人建议编写 R 扩展之前,这对我来说不是一个选择,我对此受到限制。在有人再次将其标记为重复之前,不,它不是。没有扩展不是一个选项。

最佳答案

int errval = execl("/home/vagrant/bin/Rscript", "-e", "\"x <- 2; x+1\"", (char*) NULL);

关于c++ - 从 C++ 程序调用 R(在 Linux 中),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40696610/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com