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