LNCD

Table of Contents

  • LNCD Home
  • Administration
  • Notebooks
  • Journal Club Presentations
  • Publications
  • Current Projects
  • Completed Projects
  • Current Grants
  • Datasets by Project
  • Brain ROIs and Measures
  • ️Tools And Methods
  • Big Data
  • RA Homepage
  • Undergrad Resources
  • Recent Changes
  • Maintenance
  • Site Map
  • Random Page
LNCD
Docs » GNU R

This is an old revision of the document!


GNU R

The GNU R programming language is often paired with posit's RStudio Desktop IDE and a suit of libraries (language packages) known as tidyverse (includes dplyr and ggplot2).

You can also find a web interface to Rstudio on rhea (also Remote Access).

Tutorials contains additional resources.

See

  • R Issues for log of debugged problems.
  • R versions for using specific older versions

Notes

Old Versions

On Rhea (linux server), older R versions exist for legacy pipelines and scripts. For example, see /opt/ni_tools/R/R-4.4.1/bin and packages in /opt/ni_tools/Rlib/4.4.1 (created 2025-08-11 with bump to debian 13/“trixie”, R 4.5.1 “Great Square Root”).

In a shell script, you can update the PATH to force older R.

export PATH="/opt/ni_tools/R/R-4.4.1/bin:$PATH" # default to R 4.4.1

Or call explicitly.

/opt/ni_tools/R/R-4.4.1/bin/Rscript -e '
       .libPaths("/opt/ni_tools/Rlib/4.4.1");
       print(version$version.string);
       installed.packages()["dplyr",c("Built","Version","LibPath")]
[1] "R version 4.4.1 (2024-06-14)"
                      Built                     Version 
                    "4.4.1"                     "1.1.4" 
                    LibPath 
"/home/ni_tools/Rlib/4.4.1" 

na.action for residual

When adding module residuals back to a dataframe, you need residuals() to return the same length as the input data.frame. use lm(na.action=na.exclude).

For example,

d <-  data.frame(x=c(1:4,NA),y=1:5);
m <- lm(x~y,d,na.action=na.exclude);
nrow(d);              # 5
length(m$residuals);  # 4
length(residuals(m))  # 5

This avoids the error

Error in `$<-.data.frame`(`*tmp*`, ...
  replacement has 237 rows, data has 348

MASS::select vs dplyr::select

If you load MASS after dplyr, select will be MASS::select not dplyr::select and you're likely to encounter hard-to-debug errors about unused arguments

Error in select … : unused arguments

solutions include

  1. load MASS first
  2. force select to be dplyr's version, or
  3. unload MASS if you don't need it
# load mass before dplyr to have 'select' be from dplyr
library(MASS)
library(dplyr)

# force which select (if MASS was already loaded after dplyr and overwrite the function)
select <- dplyr::select

# or unload MASS
detach("package:MASS", unload=TRUE)

# check to see
environment(select) # if "MASS", you're in for a bad time

Backlinks

  • 7T Data: merge_7t.csv
  • Merge Pet
  • ️Tools And Methods
  • AFNI
  • Python in R
  • R versions
  • Tutorials
  • Usage Profiling and benchmarking
Previous Next