Skip to content

Instantly share code, notes, and snippets.

@bschilder
Last active March 10, 2023 16:59
Show Gist options
  • Save bschilder/0c93eea041d9ecdbbd690a6c5310815c to your computer and use it in GitHub Desktop.
Save bschilder/0c93eea041d9ecdbbd690a6c5310815c to your computer and use it in GitHub Desktop.

Introduction

So I've run into an issue where I need to use the development version of an R package (MungeSumstats) to process files for a certain project. But this version requires rtracklayer >=1.59.1, which in turn requires R >=4.3 (which is currently the development version of R).

Normally, I'd simply upgrade my version of R, or create a new Docker container with the devel version of R. However, I'm using Imperial On Demand Rstudio server because it provides a RStudio GUI for interacting with files that are stored directly on my HPC project folder. This is far faster than trying to access them from my local computer when my HPC folder is mounted to it. However it also comes with several big limitations:

  • You must used conda environments to install any software. Meaning if it's not on any standard conda repos like Anaconda.org , you're out of luck.
  • You do not have sudo permissions, which just solidifies point #1.

Here are some approaches I've tried to get around this issue.

NOTE

Approach 1 did not work in my use case (on Imperial HPC).

But Approach 2 worked perfectly! Skip here to see the solution.

Approach 1

Goal: Install R-devel from source.

Instructions here https://docs.posit.co/resources/install-r-source/ If you're using an Imperial On Demand Rstudio server, you'll want to follow the instructions for RHEL/CentOS Linux, as these containers have the Red Hat Enterprise Linux (RHEL) operating system installed.

1. Download source file

Download the source file from the official R website. Then unzip it to get its contents and delete the old .tar.gz file.

cd ~
wget https://stat.ethz.ch/R/daily/R-devel.tar.gz
tar -xzvf R-devel.tar.gz
rm R-devel.tar.gz

2. Install R from source

⚠️ This is where I'm currently getting stuck, as this step requires sudo permissions, which HPC users don't have.

cd R-devel
./configure \
    --prefix=/opt/R/devel \
    --enable-R-shlib \
    --enable-memory-profiling

make
sudo make install

Approach 2

Goal: Install R packages from source.

Clone the devel version of each R package and install it from source. This conveniently (although dangerously) ignores R versioning requirements.

[Optional]: If you're trying to install these packages within a conda environment, be sure to activate your environment before proceeding to the following steps:

conda activate <my_env_name>

Create downloads folder

First, let's create a folder to store the cloned repos in:

mkdir ~/r_pkgs_src
cd ~/r_pkgs_src

Install rtracklayer

From: https://github.com/lawremi/rtracklayer

git clone https://github.com/lawremi/rtracklayer.git
R CMD INSTALL rtracklayer/

Now let's check whether the development version is installed.

We confirm the desired version by looking at the DESCRIPTION file on GitHub.

Rscript -e "packageVersion('rtracklayer')"
# [1] ‘1.59.1’

Voila! That worked!

Install MungeSumstats

Now that we have rtracklayer devel setup, let's install MungeSumstats devel.

From: https://github.com/neurogenomics/MungeSumstats

git clone https://github.com/neurogenomics/MungeSumstats.git
R CMD INSTALL MungeSumstats/

And again we'll check we have the correct version installed now. We confirm the desired version by looking at the DESCRIPTION file on GitHub.

Rscript -e "packageVersion('MungeSumstats')"
# [1] ‘1.7.19’

Summary

So now we have the development versions of both R packages installed on our machine, without actually having R >=4.3 installed anywhere! This is a useful hack in some situations, but please use it with caution and it may be circumventing some versioning controls that are intended to prevent errors.

Happy hacking! 💻

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment