Saturday, June 24, 2023

Installing R packages

 Using R packages can be fun but installing them can be difficult sometimes. The problem usually happens when the installation needs dev tools or some from one of the bioconductor repository.  Usually the instructions are as below. 

# Required packages

# Install package here
dependencies = c("Depends", "Imports", "LinkingTo"),
repos = c("",


That devtools command results into something the output below. 

Using github PAT from envvar GITHUB_PAT
Error: Failed to install 'SPRING' from GitHub:
HTTP error 401.
Bad credentials

Rate limit remaining: 59/60
Rate limit reset at: 2023-06-23 04:15:37 UTC

The problem with this is that one needs the Personal access Token (PAT) for Github API. This is really annoying problem. Also trying to install through bioconductor will update other packages sometimes. Of course, it will prompt before it does that but it can be cumbersome to check every time. What if one needs to install package/package version that is no longer available in the latest version of Bioconductor. One can set the version when installing from Bioconductor but I still have trouble finding the right package version. 

The method I am going to describe is pretty simple but will need some manual work which I think is worth it because it should not disturb your existing installations. Actually Karl Broman has nicely described this method here: 

For Github hosted R packages:
    • Download the zip file and save it locally. 
    • Unzip the file and remove the master prefix. For example, in, remove the "-main" part. Now, drag the file into terminal or type

R CMD BUILD /Users/ashish/Downloads/NetCoMi

    • This will prepare the file for installation and will result into NetCoMi_1.1.0.tar.gz file. Now this is the folder that is ready to get install on your computer. Install it using this command. 

R CMD INSTALL NetCoMi_1.1.0.tar.gz

Now you will realize that it will fail sometimes because of the dependencies are not installed. Either install them using the same method I am describing or use the install.package() function. Repeat until the package can be installed. 

For Bioconductor hosted packages: 

Bottom line is to make sure to note all the packages that are used for the analysis since sometimes updates can change your analysis output. 

No comments:

Post a Comment

Running Tarsnap

 This post is to document the procedure to run Tarsnap on MacOS. Tarsnap is basically an online service that runs on top of Amazon cloud inf...