R Configuration

Configuration

As part setting R up to work best for us, we’re also wanting to make things easier on ourselves to that we can be more productive during the “do stuff” stage.

There is a hidden file called .Rprofile which is loaded as R launches and is a place where you can place customisations of options to make your R life easier. For instance I have mine set to automatically load workflow helper packages such as {usethis} {testthat} and {devtools}. And set a few options to make R produce more warnings so that it helps me know when something might cause an issue. It’s also a good place to set some defaults such as your favourite CRAN mirror so that R doesn’t need to ask you when you go to install packages.

usethis::edit_r_profile()
 # load workflow helper packages if in interactive session
if (interactive()) {
  suppressMessages(require(devtools))
  suppressMessages(require(usethis))
  suppressMessages(require(testthat))
}


# set CRAN
options(repos = c(CRAN = "https://cloud.r-project.org/"))


# warn on partial matches
options(
  warnPartialMatchArgs = TRUE,
  warnPartialMatchDollar = TRUE,
  warnPartialMatchAttr = TRUE
)

# fancy quotes are annoying and lead to
# 'copy + paste' bugs / frustrations
options(useFancyQuotes = FALSE)

Don’t put analysis modifying options into your .Rprofile e.g. automatic loading of tidyverse. It will make the code you write less reproducible because it will start depending on these hidden settings, and it can make debugging harder.


Keyboard shortcuts

The keyboard shortcut to rule them all: Alt + Shift + K

Other useful shortcuts

Keys produces
Ctrl + Shift + M %>%
Alt + - <-
Ctrl + Shift + K knits Rmd
Ctrl + Shift + F10 Restart R
Ctrl + Alt + I Insert code chunk
Ctrl + Shift + S Source active file
Ctrl + . Go to file/function

Make your own…

Tools -> Modify Keyboard Shortcuts