繁体   English   中英

如何使用网格将python的转换字符串代码传递给R.

[英]How to pass convert string code of python to R using reticulate

我在python中有如下函数:

def print_hello():
    print("hello")

而不是使用source_python写入python文件并从文件中读取它。 我想将函数作为字符串传递并转换为R.

类似于以下事情

library(reticulate)
myPythonFunction <- "def print_hello():
     print("hello")
"

source_from_string(myPythonFunction)

print_hello()

网状包有这个功能吗?

py_run_string来执行模块,函数'print_hello'是从python env调用py$

library(reticulate)
myPythonFunction <- "def print_hello():
                         print('hello')"
py_run_string(myPythonFunction)
py$print_hello()
#hello

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM