[英]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.