16 Config files

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

16.1 R setup

Additional software:

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

16.1.1 R packages

The following R code installs all the packages I have installed currently as my base. 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
remotes::install_github(c(
    "jalvesaq/colorout"
))
remotes::install_cran(c(
    "devtools",
    "usethis"
))

## Temporary for now due to https://github.com/ropensci/RefManageR/issues/79
remotes::install_github(c(
    "ropensci/bibtex",
    "ropensci/RefManageR",
    "cboettig/knitcitations"
))

## Main packages
BiocManager::install(c(
    "biocthis",
    "brainflowprobes",
    "derfinder",
    "derfinderPlot",
    "GenomicState",
    "megadepth",
    "recount",
    "recountWorkflow",
    "recount3",
    "regutools",
    "regionReport",
    "spatialLIBD"
), 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",
    "blogdown",
    "clue",
    "corrplot",
    "getopt",
    "ggthemes",
    "googlesheets4",
    "MatrixEQTL",
    "pagedown",
    "patchwork",
    "reprex",
    "rtweet",
    "suncalc",
    "tidyverse",
    "xaringan",
    "xaringanthemer",
    "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/rsthemes",
    "gadenbuie/xaringanExtra"
))

## Private packages (you likely won't have access to them)
remotes::install_github(c(
    "LieberInstitute/LIBDpheno",
    "LieberInstitute/libdRSE"
), dependencies = TRUE)

16.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.

installed_path <- "/Users/lcollado/Dropbox/Computing/R"
installed <- dir(.libPaths())
save(installed, file = file.path(installed_path, paste0(Sys.Date(), '-installed.Rdata')))
## Load previous "installed" packaages
previous <- dir(path = installed_path, pattern = 'installed.Rdata')
load(file.path(installed_path, previous[length(previous)]), verbose = TRUE)

## Locate current pacakges
current <- dir(.libPaths())
## Missing
installed[!installed %in% current]

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

## New
current[!current %in% installed]

16.2 R config files

16.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("Solarized Light {rsthemes}")  # light theme
    rsthemes::set_theme_dark("base16 Monokai {rsthemes}") # dark theme
    rsthemes::set_theme_favorite(c(
        "Solarized Light {rsthemes}",
        "base16 Monokai {rsthemes}",
        "One Dark {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)
    }
}

16.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

16.2.3 ~/.R/Makevars

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

16.3 Git config files

16.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]
    excludesfile = /Users/lcollado/.gitignore_global
    excludesfiles = /Users/lcollado/.gitignore_global
    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]

16.3.2 ~/.gitignore_global

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

*~

## More at
## https://help.github.com/articles/ignoring-files

# R history #
#############
.Rapp.history
.Rhistory

# LaTeX stuff #
###############
*.aux
*.out


# Compiled source #
###################
*.com
*.class
*.dll
*.exe
*.o
*.so

# Packages #
############
# it's better to unpack these files and commit the raw source
# git has its own built in compression methods
*.7z
*.dmg
*.gz
*.iso
*.jar
*.rar
*.tar
*.zip

# Logs and databases #
######################
*.log
*.sql
*.sqlite

# OS generated files #
######################
.DS_Store
.DS_Store?
._*
.Spotlight-V100
.Trashes
Icon?
ehthumbs.db
Thumbs.db

16.4 JHPCE files

16.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

16.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.p
df
# https://unix.stackexchange.com/questions/48713/how-can-i-remove-duplicates-in-my-bash-history-pr
eserving-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.9
    module load conda_R/4.1
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

16.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

16.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