ICJIA / r-user-group

ICJIA R User Group
2 stars 2 forks source link

Becoming RStudio IDE power user #6

Closed bobaekang closed 4 years ago

bobaekang commented 6 years ago

Summary

Two useful RStudio IDE functionalities to improve your day-to-day R programming workflow--and more.

Main

The RStudio IDE (integrated development environment) is a powerful open-source application that is a de facto standard tool in the R community for writing programs and developing software. Although many casual R users are unaware of them, the RStudio IDE is in fact packed with useful functionalities that can significantly improve your programming workflow.

Here I present two such functionalities, namely, keyboard shortcuts and code snippets.

1. Keyboard shorcuts

RStudio IDE offers a large number of keyboard shortcuts to help you to quickly carry out some common tasks. Some of the keyboard shortcuts I find useful are as follows:

Shortcut Effect
Ctrl + 1 Move focus to Source Editor
Ctrl + 2 Move focus to Console
Ctrl + L Clear Console
Ctrl + Enter Run the current line/selection on Source Editor
Ctrl + Shift + C "Comment out" the current line on Source Editor
Ctrl + Shift + N Open a blank R script
Ctrl + Shift + M Insert a magrittr "pipe" operator, %>%
Ctrl + Shift + F10 Restart R Session
Alt + - Insert assignment operator
Alt + Shift + K Open Keyboard Shortcut Reference window

To see the full list, use the keyboard shortcut Alt + Shift + K on your RStudio IDE to open up the Keyboard Shortcut Quick Reference window. Alternatively, you can check out this article on RStudio's Support website.

Although you cannot add new keyboard shortcuts, it is possible to customize the keyboard shorcuts to make it easier for you to use. Take a look at this article on customizing keyboard shortcuts for details.

2. Code snippets

The RStudio IDE offers "code snippets", i.e. text macros that can quickly insert commonly used snippets of R code. The way it works is simply that, on Source Editor, you 1) type the snippet keyword and 2) hit the <Tab> button to get the full code snippet. It is similar to code autocompletion, but more powerful and flexible.

Some of the predefined code snippets include:

ui <- fluidPage( ${0} )

server <- function(input, output, session) {

}

shinyApp(ui, server)



You can view the full list of the currently available code snippets at: **Menu bar: Tools > Global Options > Code > Edit Snippets**.

In addition, you can add your custom code snippets on the **Edit Snippets** window. Read [this article](https://support.rstudio.com/hc/en-us/articles/204463668-Code-Snippets) on RStudio's Support website to learn more about code snippets.

### ... And more
Of course, these are only a tip of an iceberg when it comes to what the RStudio IDE offers to its users to improve their programming experience. I invite you, therefore, to look through [this list of articles on using the RStudio IDE](https://support.rstudio.com/hc/en-us/sections/200107586-Using-the-RStudio-IDE) to learn more about how to take full advantage of this powerful tool!

### Resources
* ["Code Snippets"](https://support.rstudio.com/hc/en-us/articles/204463668-Code-Snippets) by J.J. Allaire
* ["Customizing Keyboard Shortcuts"](https://support.rstudio.com/hc/en-us/articles/206382178-Customizing-Keyboard-Shortcuts) by Kevin Ushey
* [RStudio website](https://www.rstudio.com/)
* ["Using the RStudio IDE" article list](https://support.rstudio.com/hc/en-us/sections/200107586-Using-the-RStudio-IDE) on the RStudio Support website
stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.