James Laird-Smith
In this webinar, I’ll be teaching you about customising your R experience using ‘workflow shortcuts’.
It’s my collective term for a set of things that already exist:
Some of these things you already know, but some will be new (and life changing).
ctrl + c
and ctrl + v
.
Edit > Copy/Paste
from a menu item every single time?It’s a surprisingly extensible IDE.
I’m focusing on it because I know a lot of people use it.
Other magical editors:
openProject()
or applyTheme()
or even setCursorPosition()
Wrap your Markdown to a fixed width.
Style your R code.
Source: https://github.com/r-lib/styler
Allows you to to save and automatically set your own keyboard shortcuts.
#' Restart RStudio
#' @shortcut Ctrl+Alt+Shift+R
function() rstudioapi::executeCommand("restartR")
#' Go to definition
#' @shortcut Ctrl+.
function() rstudioapi::executeCommand("goToDefinition")
#' Wrap markdown text
#' @shortcut Ctrl+Alt+Shift+W
WrapRmd::wrap_rmd_addin
usethis::edit_r_profile()
.There are two main things you want to bear in mind.
You don’t want to compromise the reproducibility of your scripts,
options(max.print = 40)
is acceptable, because it only affects the output that you see at the console.library(tidyverse)
is not acceptable, because readers of your script then won’t know that you’ve loaded the package.You don’t want to unconditionally load packages.
options(max.print = 40)
options(connectionObserver = NULL)
# ^ connectionObserver at work just gets in the way.
options(tidyverse.quiet = TRUE)
options(styler.cache_root = "styler-perm")
Also includes packages options, which are fine to set.
Work out whether I am on RStudio or not.
I have a whole Twitter thread about how this is the best way to do this and other methods are wrong.
This code then enables you to write other code more easily like if(on_rstudio())
etc.
Helper functions at_work()
and my_email()
.
options(
usethis.full_name = "James Laird-Smith",
usethis.description = list(
"Authors@R" = utils::person(
"James", "Laird-Smith",
email = my_email(),
role = c("aut", "cre"),
comment = c(ORCID = "0000-0003-1175-4046")
),
Version = "0.0.0.9000"
),
usethis.overwrite = TRUE
)
This way my email changes depending on whether I’m at work or at home.
setHook("rstudio.sessionInit", function(newSession) {
rstudioapi::writeRStudioPreference("editor_keybindings", "vim")
rstudioapi::writeRStudioPreference("save_workspace", "never")
rstudioapi::writeRStudioPreference("always_save_history", FALSE)
rstudioapi::writeRStudioPreference("save_files_before_build", TRUE)
}, action = "append")
I don’t want to load the shrtcts package every session, so I wrap it in a function instead.
Tip: you can start all your convenience functions with your initials so you get auto-complete.
I’ve created an R Markdown template called customiser1.
Questions?