17 Config files

Here are some of my configuration files for working R and JHPCE.

17.1 R setup

So in macOS I use:

## From https://mac.r-project.org/bin/
# sudo R
source("https://mac.R-project.org/bin/install.R")
install.libs("all")

and on winOS I install Rtools (latest version) from https://cran.r-project.org/bin/windows/Rtools/.

Additional software:

You might also be interested in checking out our older onboarding setup materials.

17.1.1 R packages

The following R code installs all the packages I have installed currently as my base. Many of them are packages I have made or contributed to as you can see at lcolladotor.github.io/pkgs. As I explore packages, I might try new ones that are not in this list.

## Install from scratch
if (!requireNamespace("remotes", quietly = TRUE))
    install.packages("remotes")
remotes::install_cran("BiocManager")
BiocManager::version()

## Rprofile packages
if (.Platform$OS.type != "windows") {
    remotes::install_github(
        "jalvesaq/colorout"
    )
}
remotes::install_github("gaborcsardi/prompt")

remotes::install_github(c(
    "gadenbuie/rsthemes"
))
remotes::install_cran("suncalc")
rsthemes::install_rsthemes(include_base16 = TRUE)
remotes::install_cran(c(
    "devtools",
    "usethis"
))

## Main packages
BiocManager::install(c(
    "biocthis",
    "brainflowprobes",
    "derfinder",
    "derfinderPlot",
    "GenomicState",
    "megadepth",
    "qsvaR",
    "recount",
    "recountWorkflow",
    "recount3",
    "regutools",
    "regionReport",
    "spatialLIBD",
    "TREG"
), dependencies = TRUE, update = FALSE)

## LIBD packages
remotes::install_github(c(
    "LieberInstitute/jaffelab",
    "LieberInstitute/recount.bwtool",
    "LieberInstitute/sgejobs",
    "LieberInstitute/shinycsv"
), dependencies = TRUE)

## CRAN packages
remotes::install_cran(c(
    "ari",
    "bookdown",
    "blogdown",
    "clue",
    "corrplot",
    "getopt",
    "ggpubr",
    "ggrepel",
    "ggthemes",
    "googlesheets4",
    "MatrixEQTL",
    "pagedown",
    "patchwork",
    "postcards",
    "reprex",
    "rsconnect",
    "rtweet",
    "tidyverse",
    "xaringan",
    "xaringanthemer",
    "UpSetR",
    "VennDiagram"
))

## Bioc packages
BiocManager::install(c(
    "BiocCheck",
    "ComplexHeatmap",
    "ExploreModelMatrix",
    "iSEE",
    "scater",
    "scran",
    "sva",
    "variancePartition"
), update = FALSE)

## GitHub packages
remotes::install_github(c(
    "cloudyr/rmote",
    "gadenbuie/xaringanExtra",
    "clauswilke/colorblindr",
    ## Install from GitHub due to https://github.com/immunogenomics/harmony/issues/145
    "immunogenomics/harmony", 
    "satijalab/azimuth"
))
 ## Related to https://github.com/gusevlab/fusion_twas/issues/14
remotes::install_github("carbocation/plink2R/plink2R", ref = "carbocation-permit-r361")

## Packages I only install at JHPCE
remotes::install_github("muschellij2/clusterRundown")
remotes::install_github("cloudyr/rmote")

17.1.1.1 Previously installed

As I described in my blog post on updating R, I also like to saved my list of currently installed packages.

## Save currently installed packages
installed_path <- ifelse(
    .Platform$OS.type != "windows",
    "~/Dropbox/Computing/R",
    "C:/Users/fellg/Dropbox/Computing/R"
)

installed <- dir(.libPaths())
save(installed, file = file.path(installed_path, paste0(Sys.Date(), '-installed.Rdata')))
## Load previous "installed" packages
previous <- dir(path = installed_path, pattern = 'installed.Rdata')
load(file.path(installed_path, previous[length(previous)]), verbose = TRUE)

## Locate current packages
current <- dir(.libPaths())

## Missing ones
installed[!installed %in% current]

## Install missing packages
BiocManager::install(installed[!installed %in% current])

## List new R packages
current[!current %in% installed]

You might also benefit from watching this video and checking the companion notes.

If you want to install multiple R and Bioconductor versions, then you might find this second video and companion notes useful.

17.2 R config files

17.2.1 ~/.Rprofile

Edit it with usethis::edit_r_profile(). Don’t add any analysis packages here as discussed in the “what they forgot to teach you about R” workshop.

## Change colors
# Source https://github.com/jalvesaq/colorout
if(Sys.getenv('TERM') %in% c("term", "xterm-256color", "cygwin", "screen")) {
    if (!requireNamespace("colorout", quietly = TRUE) & .Platform$OS.type != 'windows') {
        cat('To install colorout use: remotes::install_github("jalvesaq/colorout")\n')
    }
}

# https://bookdown.org/yihui/blogdown/global-options.html
options(blogdown.author = 'L. Collado-Torres')
options(blogdown.ext = '.Rmd')
options(blogdown.insertimage.usebaseurl = TRUE)

## From RStudio::conf 2019 Building Tidy Tools
if (interactive()) {
    suppressMessages(require("devtools"))
    suppressMessages(require("usethis"))
    suppressMessages(require("testthat"))
    
    options(
        warnPartialMatchArgs = TRUE,
        warnPartialMatchDollar = TRUE,
        warnPartialMatchAttr = TRUE
    )
}

## https://blog.rstudio.com/2013/06/10/rstudio-cran-mirror/
options(repos = c(CRAN = "https://cloud.r-project.org/"))

## For usethis::use_git()
options(usethis.protocol = "ssh")

## For usethis
options(
    usethis.full_name = "Leonardo Collado-Torres",
    usethis.description = list(
        `Authors@R` = 'c(
    person("Leonardo", "Collado-Torres", role = c("aut", "cre"),
    email = "lcolladotor@gmail.com", comment = c(ORCID = "0000-0003-2140-308X"))
    )'
    )
)

## For biocthis
options("biocthis.pkgdown" = TRUE)
options("biocthis.testthat" = TRUE)

## From https://www.garrickadenbuie.com/project/rsthemes/
if (interactive() && requireNamespace("rsthemes", quietly = TRUE)) {
    # Set preferred themes if not handled elsewhere..
    rsthemes::set_theme_light("base16 Monokai {rsthemes}")  # light theme
    rsthemes::set_theme_dark("base16 Pop {rsthemes}") # dark theme
    rsthemes::set_theme_favorite(c(
        "base16 Monokai {rsthemes}",
        "base16 Pop {rsthemes}",
        "base16 Brewer {rsthemes}",
        "One Dark {rsthemes}",
        "Solarized Light {rsthemes}"
    ))

    # Whenever the R session restarts inside RStudio...
    setHook("rstudio.sessionInit", function(isNewSession) {
        # Automatically choose the correct theme based on time of day
        ## Used rsthemes::geolocate() once
        rsthemes::use_theme_auto(lat = 39.2891, lon = -76.5583)
    }, action = "append")
}

## From https://twitter.com/hadleywickham/status/1113542388033699840
if(interactive()) {
    if (!requireNamespace("prompt", quietly = TRUE)) {
        cat('To install prompt use: remotes::install_github("gaborcsardi/prompt")\n')
    } else {
        prompt::set_prompt(prompt::prompt_git)
    }
}

17.2.2 ~/.Renviron

Edit it with usethis::edit_r_environ(). Here you can keep personal access tokens (PATs).

GITHUB_PAT=something_provite
TWITTER_PAT=a_private_file_path

17.2.3 ~/.R/Makevars

I don’t have anything in this file since R 4.0 on my macOS laptop.

17.3 Git config files

17.3.1 ~/.gitconfig

Edit it with usethis::edit_git_config(). Note that my editor is TextMate2 on macOS which can be accessed through the mate -w command.

[user]
    name = Leonardo Collado Torres
    email = lcolladotor@gmail.com
[core]
    editor = mate -w
    ignorecase = true
[difftool "sourcetree"]
    cmd = opendiff \"$LOCAL\" \"$REMOTE\"
    path = 
[mergetool "sourcetree"]
    cmd = /Applications/SourceTree.app/Contents/Resources/opendiff-w.sh \"$LOCAL\" \"$REMOTE\" -ancestor \"$BASE\" -merge \"$MERGED\"
    trustExitCode = true
[alias]
    ci = commit
    st = status
    br = branch
    co = checkout
    last = log -1 HEAD
    visual = gitk
[push]
    default = simple
[svn]
    rmdir = true
[commit]

17.3.2 ~/.gitignore_global

Edit it with usethis::edit_git_ignore(). These files are ignored by default by git on my computer.

I no longer have this file since many people didn’t have it, so they would see files with git status that I wouldn’t. To simplify things, I have deleted this (for now).

17.4 JHPCE files

To configure your computer with JHPCE, you might want to check this video and companion notes for macOS

or this other video and companion notes for winOS.

These videos also talk about GitHub and local git setup on your laptop.

17.4.1 ~/.sge_request

This file configures the default SGE requests under qsub and qrsh.

# Check http://www.biostat.jhsph.edu/bit/cluster-usage.html for more instructions
#
# Set defaults for mem_free and h_vmem
-l mem_free=12G,h_vmem=12G
#
# Set the standard value for stack size limit
# (needed for some programs to run properly when h_vmem is set)
-l h_stack=256M
#
# Set a default maximum file size that an SGE job can create
-l h_fsize=100G
# Define my email
-M YOUR_EMAIL@gmail.com
# To get an email on a job use -m e
# Keep in mind the limits with sending emails from
# https://jhpce.jhu.edu/email-qsub

17.4.2 ~/.bashrc

This is the main configuration file for JHPCE, but it’s really for any linux system. Some of the commands have to change when working on macOS.

# .bashrc

# Source global definitions
if [ -f /etc/bashrc ]; then
    . /etc/bashrc
fi

# User specific aliases and functions
# Auto-complete command from history
# http://lindesk.com/2009/04/customize-terminal-configuration-setting-bash-cli-power-user/
export INPUTRC=~/.inputrc
# http://www.biostat.jhsph.edu/~afisher/ComputingClub/webfiles/KasperHansenPres/IntermediateUnix.pdf
# https://unix.stackexchange.com/questions/48713/how-can-i-remove-duplicates-in-my-bash-history-preserving-order
export HISTCONTROL=ignoreboth:erasedups
export HISTSIZE=20000
shopt -s histappend
shopt -s cmdhist

# http://superuser.com/questions/384769/alias-rm-rm-i-considered-harmful
alias rmi='rm -i'

# Change command prompt
# http://www.cyberciti.biz/tips/howto-linux-unix-bash-shell-setup-prompt.html
# http://www.cyberciti.biz/faq/bash-shell-change-the-color-of-my-shell-prompt-under-linux-or-unix/
# https://bbs.archlinux.org/viewtopic.php?id=48910
# previous in enigma2: "[\u@\h \W]\$ "
# previously in mac: "\h:\W \u\$ "
export PS1="\[\e[0;33m\]\A \W \$ \[\e[m\]"

# LIDB projects
alias labold="cd /dcl01/lieber/ajaffe/lab"
alias lab="cd /dcl01/ajaffe/data/lab"

## 10X genomics
alias single="cd /dcl01/ajaffe/data/lab/singleCell"
alias spatialold="cd /dcl02/lieber/ajaffe/SpatialTranscriptomics/HumanPilot"
alias spatial="cd /dcl02/lieber/ajaffe/SpatialTranscriptomics/LIBD"
alias matt="cd /dcl01/lieber/ajaffe/Matt/MNT_thesis/snRNAseq/10x_pilot_FINAL"

## Team home directories
alias dcl01="cd /dcl01/lieber/lcolladotor"
alias dcl02="cd /dcl02/lieber/lcolladotor"
alias dcs04="cd /dcs04/lieber/lcolladotor"

## Creating modules
# https://lmod.readthedocs.io/en/latest/050_lua_modulefiles.html
alias modsrc="cd /jhpce/shared/jhpce/libd"
alias modlua="cd /jhpce/shared/jhpce/modulefiles/libd"

# colors
# http://norbauer.com/notebooks/code/notes/ls-colors-and-terminal-app
# used BSD pattern ExGxFxDxBxEgEdxbxgxhxd on http://geoff.greer.fm/lscolors/
# that tool does not specify the colors, which I did by looking manually at
# http://blog.twistedcode.org/2008/04/lscolors-explained.html
# and the norbauer.com site previously mentioned
alias ls="ls --color=auto"
#export LS_COLORS="di=1;34;40:ln=1;36;40:so=1;35;40:pi=1;93;40:ex=1;31;40:bd=1;34;46:cd=1;34;43:su
=0;41:sg=0;46:tw=0;47:ow=0;43"
## After switching to RStudio:
# https://askubuntu.com/questions/466198/how-do-i-change-the-color-for-directories-with-ls-in-the-
console
export LS_COLORS="di=0;32:ln=0;36:so=0;35:pi=0;93:ex=0;31:bd=0;34;46:cd=0;34;43:su=0;41:sg=0;46:tw=0;47:ow=0;43:fi=0;33"

# Uncomment below for Mac and comment the two previous commands
#export CLICOLOR=1
#export LSCOLORS="ExGxFxDxBxEgEdxbxgxhxd"

## For setup:
# http://erniemiller.org/2011/12/12/textmate-2-rmate-awesome/
## For laptop config:
# http://jonsimpson.co.uk/log/2011/rmate-ssh-remoteforward
## rmate port
# https://github.com/textmate/rmate
export RMATE_PORT="SOME_PORT_YOU_CHOOSE"

## Load the git module by default when qrsh/qsub
## thanks to Jiong Yang
if [[ $HOSTNAME == compute-* ]] || [[ $HOSTNAME == transfer-* ]]; then
    echo "Adding LIBD modules"
    module use /jhpce/shared/jhpce/modulefiles/libd
    echo "Loading git"
    module load git
    module load git-status-size/github
    module load git-lfs/2.8.0
    module load rmate/1.5.10
    module load conda_R/4.2
fi

## To deal with running nextflow without requesting much more memory
## https://jhpce.jhu.edu/question/why-do-i-get-memory-errors-when-running-java/
export _JAVA_OPTIONS="-Xms5g -Xmx6g"

## From https://twitter.com/fellgernon/status/1258455434073124865?s=20
## and https://www.cyberciti.biz/tips/understanding-linux-unix-umask-value-usage.html
umask u=rwx,g=rwx,o= ## equivalent to umask 007

For more information on rmate and rmote and how it relates to these configuration files, check this video and companion notes.

17.4.3 ~/.bash_profile

This file is basically empty, since all the information is contained in the ~/.bashrc. That was the recommended setup a few years ago when I asked JHPCE’s admins.

# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
    . ~/.bashrc
fi

17.4.4 ~/.inputrc

Useful for altering the behavior of the up and down arrow keys. See the companion lines on the ~/.bashrc file.

#Page up/page down
"\e[B": history-search-forward
"\e[A": history-search-backward

$include /etc/inputrc

© 2011-2021. All thoughts and opinions here are my own. The icon was designed by Mauricio Guzmán and is inspired by Huichol culture; it represents my community building interests.

Published with Bookdown