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

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))

## Rprofile packages
if (.Platform$OS.type != "windows") {

rsthemes::install_rsthemes(include_base16 = TRUE)

## Main packages
), dependencies = TRUE, update = FALSE)

## LIBD packages
), dependencies = TRUE)

## CRAN packages

## Bioc packages
), update = FALSE)

## GitHub packages
    ## Install from GitHub due to https://github.com/immunogenomics/harmony/issues/145
 ## 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("cloudyr/rmote") 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",

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()) {
        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
    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
        "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 {

17.2.2 ~/.Renviron

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


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.

    name = Leonardo Collado Torres
    email = lcolladotor@gmail.com
    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
    ci = commit
    st = status
    br = branch
    co = checkout
    last = log -1 HEAD
    visual = gitk
    default = simple
    rmdir = true

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

# 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
## After switching to RStudio:
# https://askubuntu.com/questions/466198/how-do-i-change-the-color-for-directories-with-ls-in-the-
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

## 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

## 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

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