System2 to call Python2 and Python3 inside R

佐手、 提交于 2020-01-03 02:30:36

问题


I want to execute python with R but

> system2('python2', args =  c('-c', 'print', 'hello'), stdout = TRUE)
[1] ""

prints "" instead of hello with python2.

Then again

> system2('python3', args =  c('-c', 'print("hello")'), stdout = TRUE, stderr = TRUE)
sh: -c: line 0: syntax error near unexpected token `('
sh: -c: line 0: `'python3' -c print("hello") 2>&1'
character(0)
attr(,"status")
[1] 2
Warning message:
running command ''python3' -c print("hello") 2>&1' had status 2 

prints a lot of warnings. The intended output was hello.

How to print hello with python2/python3 inside R using system2?

来源:https://stackoverflow.com/questions/45426902/system2-to-call-python2-and-python3-inside-r

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!