簡體   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