如何使用网状将 python 的转换字符串代码传递给 R
How to pass convert string code of python to R using reticulate
我在 python 中的功能如下:
def print_hello():
print("hello")
而不是写入 python 文件并使用 source_python
从文件中读取它。我只想将函数作为字符串传递并转换为 R.
类似于以下内容
library(reticulate)
myPythonFunction <- "def print_hello():
print("hello")
"
source_from_string(myPythonFunction)
print_hello()
网纹包有这个功能吗??
py_run_string
执行模块,函数 'print_hello' 由 py$
从 python env 调用
library(reticulate)
myPythonFunction <- "def print_hello():
print('hello')"
py_run_string(myPythonFunction)
py$print_hello()
#hello
我在 python 中的功能如下:
def print_hello():
print("hello")
而不是写入 python 文件并使用 source_python
从文件中读取它。我只想将函数作为字符串传递并转换为 R.
类似于以下内容
library(reticulate)
myPythonFunction <- "def print_hello():
print("hello")
"
source_from_string(myPythonFunction)
print_hello()
网纹包有这个功能吗??
py_run_string
执行模块,函数 'print_hello' 由 py$
library(reticulate)
myPythonFunction <- "def print_hello():
print('hello')"
py_run_string(myPythonFunction)
py$print_hello()
#hello