Add rpy2 to the dependencies
- add a Jupyter notebook that allows to install all project-external dependencies regarding R and R packages - adjust the GitHub Action workflow to also install R and the R packages used within the project - add a `init_r` module that initializes all R packages globally once the `urban_meal_delivery` package is imported
This commit is contained in:
parent
84876047c1
commit
b0f2fdde10
10 changed files with 2152 additions and 52 deletions
28
src/urban_meal_delivery/init_r.py
Normal file
28
src/urban_meal_delivery/init_r.py
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
"""Initialize the R dependencies.
|
||||
|
||||
The purpose of this module is to import all the R packages that are installed
|
||||
into a sub-folder (see `config.R_LIBS_PATH`) in the project's root directory.
|
||||
|
||||
The Jupyter notebook "research/r_dependencies.ipynb" can be used to install all
|
||||
R dependencies on a Ubuntu/Debian based system.
|
||||
"""
|
||||
|
||||
from rpy2.rinterface_lib import callbacks as rcallbacks
|
||||
from rpy2.robjects import packages as rpackages
|
||||
|
||||
|
||||
# Suppress R's messages to stdout and stderr.
|
||||
# Source: https://stackoverflow.com/a/63220287
|
||||
rcallbacks.consolewrite_print = lambda msg: None # pragma: no cover
|
||||
rcallbacks.consolewrite_warnerror = lambda msg: None # pragma: no cover
|
||||
|
||||
|
||||
# For clarity and convenience, re-raise the error that results from missing R
|
||||
# dependencies with clearer instructions as to how to deal with it.
|
||||
try: # noqa:WPS229
|
||||
rpackages.importr('forecast')
|
||||
rpackages.importr('zoo')
|
||||
|
||||
except rpackages.PackageNotInstalledError: # pragma: no cover
|
||||
msg = 'See the "research/r_dependencies.ipynb" notebook!'
|
||||
raise rpackages.PackageNotInstalledError(msg) from None
|
||||
Loading…
Add table
Add a link
Reference in a new issue