Navigate to implementation: Mouse over + F2 or CTRL + Mouse Click
Un-/Comment line/selection: Ctrl + Shift + C
Select all occurrences of the selected variable: CTRL + SHIFT + ALT + M
Cursor-Select multiple lines: Ctrl + Alt + Up/Down
Profiling
Profiling of code can be done within R-Studio with the package profvis, a descirption of the process is given here . In short, pass the code to be profiled as argument to the function profvis:
profvis({
data(diamonds, package = "ggplot2")
plot(price ~ carat, data = diamonds)
m <- lm(price ~ carat, data = diamonds)
abline(m, col = "red")
})
If you want to see if a vector contains a single value, any(x == 10) is much faster than 10 %in% x because testing equality is simpler than testing set inclusion.
unlist(x, use.names = FALSE) is much faster than unlist(x).
A pernicious source of slow R code is growing an object with a loop. Whenever you use c(), append(), cbind(), rbind(), or paste() to create a bigger object, R must first allocate space for the new object and then copy the old object to its new home. If you repeat this many times, like in a for loop, this can be quite expensive.
External sources
General R
List of useful external information about R and RStudio.
From: https://wiki.esqlabs.com/wiki/Software/R_tips_and_tricks
RStudio
Useful shortcuts
Profiling
Profiling of code can be done within R-Studio with the package profvis, a descirption of the process is given here . In short, pass the code to be profiled as argument to the function profvis:
Markdown
R Markdown Cookbook
R Markdown Cookbook
References in R Markdown using Zotero
Performance
If you want to see if a vector contains a single value, any(x == 10) is much faster than 10 %in% x because testing equality is simpler than testing set inclusion. unlist(x, use.names = FALSE) is much faster than unlist(x). A pernicious source of slow R code is growing an object with a loop. Whenever you use c(), append(), cbind(), rbind(), or paste() to create a bigger object, R must first allocate space for the new object and then copy the old object to its new home. If you repeat this many times, like in a for loop, this can be quite expensive.
External sources
General R
List of useful external information about R and RStudio.
ggplot2
Here is a nice Cheatsheet on Theme options in ggplot2: https://github.com/claragranell/ggplot2/blob/main/ggplot_theme_system_cheatsheet.pdf
And one of the most extensive guides on how you can change the looks of your ggplot2 graphs: https://www.cedricscherer.com/2019/08/05/a-ggplot2-tutorial-for-beautiful-plotting-in-r/