在R包中添加对(Python)命令行程序的调用的最佳方法? [英] Best way to add a call to a (Python) command line program in an R package?
问题描述
我制作了一个R包,其中包括,调用python命令行程序与以下代码:
I made an R package that, among other things, calls a python command line program with the following code:
py_loc = paste('C:/Python33/python.exe',system.file('exec', 'example.py', package='examplePackage'))
command <- paste(py_loc,"-e example")
它运行程序 example.py $ c $在
示例
包含Python可执行文件的 exec
文件夹 C:/ Python33 /python.exe
。因为我使用Windows,并且我想与其他Windows用户(但非Windows用户)共享它,我不能使用rPython来编写代码。
问题是 python.exe
将位于其他用户不同的地方。
It runs the program example.py
in the exec
folder of my example
package with the Python executable C:/Python33/python.exe
. Because I use Windows, and I want to share it with other Windows users (but also non-Windows users) I can't use rPython to write the code.
The problem is that the python.exe
will be located somewhere different for other users.
我的想法是添加一个 config
文件,您可以在其中设置Python可执行文件的位置,它作为函数的输入。是否有更好的方法来添加对R包中的(Python)命令行程序的调用?
My idea was to add a config
file where you can set the location of the Python executable, or to ask it as the input of the function. Is there a better way to add a call to a (Python) command line program in an R package?
推荐答案
不能在Windows上工作。
然而,rPython的作者为Windows编写了一个版本:
https://github.com/cjgb/rPython-win
rPython和rPython-win都需要先安装Python,然后将R包指向。
我最近学到了另一个包装包,PythonInR: https://bitbucket.org/Floooo/ pythoninr /
我没有尝试过,但文档看起来很大。
"rPython does not work on Windows yet. " However the author of rPython wrote a version for Windows: https://github.com/cjgb/rPython-win Both rPython and rPython-win require that you install Python first, then "point" the R package to it. I recently learned of another 'wrapper' package, PythonInR: https://bitbucket.org/Floooo/pythoninr/ I have not tried it out but the documentation looks substantial.
这篇关于在R包中添加对(Python)命令行程序的调用的最佳方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!