I have two scripts open in an RStudio environment. One Python_script.py and r_script.R
I want to be able to save a variable in either script and be able to call that variable from the other, in the other language.
Thanks in advance
I have two scripts open in an RStudio environment. One Python_script.py and r_script.R
I want to be able to save a variable in either script and be able to call that variable from the other, in the other language.
Thanks in advance
You can do it using the reticulate package:
Python_script.py (run in R studio):
import numpy as np
x = np.random.rand(100)
quit
r_script.R:
library(reticulate)
py$x
#> [1] 0.144915024 0.824587306 0.781184497 0.442235857 0.848616639
# [6] 0.474798959 0.426096485...
y <- 1:10
Python_script2.py:
r.y
# >>> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
Or just run reticulate::source_python('Python_script.py') in R