交互原理
藉助了reticulate這個包,
其中兩個工具的模塊包加載方式在R中是import(“math”) ;在Python中是import math
調用模塊包後執行結果,執行方式:R中是math$sqrt(20);python中是math.sqrt(20)
python執行結果
R語言執行結果
整體code
library(reticulate)
py_available() # 檢查python是否存在
os <- import("os") # 調用python的os包
os$getcwd() # 在R中執行python的os包中的命令
math<-import("math") # R語言導入math包
result1<-math$sqrt(20) # R語言中使用Python的math函數包的功能模塊,進行計算
print(result1) # 查看調用python包運行的結果
藉助了reticulate這個包,其中兩個工具的模塊包加載方式在R中是import(“math”) ;在Python中是import math
調用模塊包後執行結果,執行方式:R中是math$sqrt(20);python中是math.sqrt(20)