参考使用homebrew管理linux和mac软件安装homebrew、mamba和Python
mamba create -y -n jlpy python=3.10
mamba activate jlpy
mamba install matplotlib
which python
# /opt/homebrew/Caskroom/mambaforge/base/envs/jlpy/bin/python
在R中运行,找到R_HOME
R.home()
# /Library/Frameworks/R.framework/Resources
在Julia中运行
using Pkg
Pkg.add(["PyCall","RCall"])
ENV["PYTHON"]="/opt/homebrew/Caskroom/mambaforge/base/envs/jlpy/bin/python"
Pkg.build("PyCall")
ENV["R_HOME"] = "/Library/Frameworks/R.framework/Resources"
Pkg.build("RCall")
还有许多用法,可以参考官网
using RCall
@rimport base as rbase
rbase.sum([1, 2, 3])
# RObject{IntSxp}
# [1] 6
跟在R中写代码已经没什么区别了
R"
library(ggplot2)
qplot(iris$Sepal.Length,iris$Sepal.Width,color=iris$Species)
ggsave('iris.png')
"
还有许多用法,可以参考官网
using PyCall
math = pyimport("math")
math.sin(math.pi / 4) # returns ≈ 1/√2 = 0.70710678...
plt = pyimport("matplotlib.pyplot")
x = range(0;stop=2*pi,length=1000); y = sin.(3*x + 4*cos.(2*x));
plt.plot(x, y, color="blue", linewidth=2.0, linestyle="--")
plt.show()
https://juliainterop.github.io/RCall.jl/stable/
https://github.com/JuliaPy/PyCall.jl
联系客服