Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

To incorporate an R script into a Python Poetry/GitHub Actions repository, the following minimum modifications are required:

  1. Add R to the dependencies of your Python Poetry project. This can be done by adding the following line to your poetry.lock file:
library(r-base)
  1. Install the required R packages using the following command in your workflow file:
Rscript -e "install.packages('package_name')"

Replace package_name with the name of the R package you want to install.

  1. Use the 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
  1. In your Python code, import the 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.