System2在R里面调用Python2和Python3

时间:2017-07-31 23:47:21

标签: python r system stdout stdin

我想用R执行python但是

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

使用python2打印""而不是hello

然后再次

> 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 

打印了很多警告。目标输出为hello

如何使用system2在R里面用python2 / python3打印你好?

0 个答案:

没有答案