call python with system() in R to run a python script emulating the python console

后端 未结 3 1531
感情败类
感情败类 2020-12-31 11:19

I want to pass a chunk of Python code to Python in R with something like system(\'python ...\'), and I\'m wondering if there is an easy way to emulate the pytho

3条回答
  •  借酒劲吻你
    2020-12-31 11:52

    The system command has an option called intern = FALSE. Make this TRUE and Whatever output was just visible before, will be stored in a variable.

    Now run your system command with this option and you should get your output directly in your variable. Like this

    tmp <- system("python -c 'print \"hello world\"'",intern=T)
    

提交回复
热议问题