Interaction between R language and Python

Interaction principle

With the help of the package reticulate,
the module package loading method of two of the tools is import("math") in R; in Python, import math
calls the execution result of the module package. The execution method: math$sqrt(20 ); math.sqrt(20) in python

python execution result

Insert picture description here

R language execution results

Insert picture description here

Overall 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包运行的结果

With the help of the package reticulate, the module package loading method of two of the tools is import("math") in R; in Python, import math
calls the execution result of the module package. The execution method: math$sqrt(20 ); math.sqrt(20) in python

Guess you like

Origin blog.csdn.net/tandelin/article/details/106466101