1 | initial version |
To incorporate an R script into a Python Poetry/GitHub Actions repository, the following minimum modifications are required:
library(r-base)
Rscript -e "install.packages('package_name')"
Replace package_name
with the name of the R package you want to install.
rpy2
package to call R functions from Python. You can install this package by adding the following line to your requirements.txt file:rpy2==3.4.2
rpy2
module and use the robjects
subpackage to call R functions. For example:import rpy2.robjects as robjects
r_sum = robjects.r("function(a, b) {a + b}")
result = r_sum(1, 2)
print(result[0])
In this example, we define an R function that adds two numbers, and call it from Python using the robjects.r
method. The result is returned as an R vector, so we need to access the first element of that vector using result[0]
.
By following these steps, you should be able to incorporate an R script into your Python Poetry/GitHub Actions repository.