Skip to content

Commit

Permalink
Merge pull request #374 from hpcleuven/feature/R_devtools
Browse files Browse the repository at this point in the history
Feature/r devtools
  • Loading branch information
WouterVanAssche authored Dec 20, 2023
2 parents d23e0f9 + e02fd0d commit 3cc830e
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 11 deletions.
76 changes: 76 additions & 0 deletions source/software/r_devtools.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
.. _r_devtools:

Installing R packages with devtools
===================================

Introduction
~~~~~~~~~~~~

The installation of some R packages may require the use of devtools.
Devtools is an R package that facilitates the installation of other
R packages from github, gitlab, bitbucket or other repositories.
In what follows github will be used as an example. Please consult the
devtools_ documentation for examples of other repositories.

Depending on how your R library is managed, you will need a slightly different
approach to use and install devtools.

.. note::

When consulting the devtools documentation, make sure that it is the correct version!
It should match the devtools version included in the R module. To check which devtools version is installed:

.. code-block:: r
library(devtools)
sessioninfo::session_info()
Installing in a local R library
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

If you manage your R packages in a :ref:`local R library<r_package_management_standard_lib>` under ``$VSC_DATA/R``
while using a centrally installed R module, you can use the devtools package included in the module.
You will need to execute the following commands in the R console:

.. code-block:: r
> # First check that the R library path points to your local R library:
> .libPaths()
> # Set the R library path if this is not the case.
> .libPaths("/data/leuven/XXX/vscXXXXX/R/")
> # Load devtools and e.g. install your package from github:
> library(devtools)
> devtools::install_github("Developer/Package")
.. note::

The devtools package is **not** included in "-bare" R modules, e.g. R/4.0.2-foss-2018a-bare.

Installing in a conda environment
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

If you are using conda to manage your R packages, you should first install
devtools in your conda environment. The following steps assume that you
already have a conda environment named "science". If you do not yet have
a conda environment, First create a :ref:`conda environment<r_package_management_conda>`.
In the following example, it is assumed that your miniconda environment is installed in ``$VSC_DATA/miniconda3``.

.. code-block:: bash
$ # Activate your conda environment and install devtools
$ source activate science
$ conda install -c conda-forge r-devtools
$ # Launch R
$ R
.. code-block:: r
> # Check that the R library path points to your conda R library
> .libPaths()
> # Set the R library path if this was not the case.
> .libPaths("/data/leuven/XXX/vscXXXXX/miniconda3/envs/science/lib/R/library")
> # Load devtools and e.g. install your package from github:
> library(devtools)
> devtools::install_github("Developer/Package")
.. _devtools: https://www.rdocumentation.org/packages/devtools
28 changes: 18 additions & 10 deletions source/software/r_package_management.rst
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
.. _R_package_management:

R package management
====================

Introduction
------------

Most of the useful R packages come in the form of packages that can be
installed separately. Some of those are part of the default installation
on VSC infrastructure. Given the astounding number of packages, it is
not sustainable to install each and everyone system wide. Since it is
very easy for a user to install them just for himself, or for his
research group, that is not a problem though. Do not hesitate to contact
support whenever you encounter trouble doing so.
Most of the useful R packages can be installed separately. Some of those are
part of the centrally installed R modules. However, given the astounding number of
packages, it is not sustainable to install each and everyone of them system wide.
Fortunately, it is very easy for users to install R packages themselves.
If you do encounter problems when doing so, do not hesitate to contact support.

.. _r_package_management_standard_lib:

Standard R package installation
-------------------------------
Expand Down Expand Up @@ -45,8 +47,12 @@ library, .e.g., ::

$ module load GSL/2.5-GCC-6.4.0-2.28

Note that R packages often depend on the specific R version they were installed
for, so you may need to reinstall them for other versions of R.
.. note::

R packages often depend on the specific R version they were installed
for, so you may need to reinstall them for other versions of R.

.. _r_package_management_conda:

Installing R packages using conda
---------------------------------
Expand Down Expand Up @@ -176,4 +182,6 @@ original state, use the following command
More information
~~~~~~~~~~~~~~~~

Additional information about conda can be found on its `documentation site <https://conda.readthedocs.io/en/latest/>`__.
Additional information about conda can be found on its `documentation site <https://docs.conda.io/en/latest/>`__.

For installing R packages from github or other repositories see also :ref:`R devtools<r_devtools>`:
2 changes: 1 addition & 1 deletion source/software/software_development.rst
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ Libraries
perl_package_management
python_package_management
r_package_management

r_devtools

0 comments on commit 3cc830e

Please sign in to comment.