Peter’s R — Navigating RStudio
My last story was about NLP resources in R. This time I want to show you some shortcuts and Keyboard Maestro macros, I use for my work with RMarkdown within the RStudio IDE.
RStudio shortcuts
RStudio contains a bunch of shortcuts. You will find them with ⌥ ⇧K. There are over 100 shortcuts. Most of them need two or three keystrokes. Within a notebook or a RMarkdown document I often use ⌘ ⇧I to insert a chunk of R code, ⌘F to open the find menus and ⌥- to get the assignment operator <- .
Keyboard Maestro
There is also a shortcut for the pipe operator %<%, ^ ⇧M. Because I use the assignment and the pipe operators most, I created a Keyboard Maestro macro for the pipe, which lies near to the assignment shortcuts: .-.
This is more convenient to me, because the three characters are easy to reach on the keyboard.
I use RStudio on a daily base for different tasks. Most scripts include these four operations from dplyr:
- filter()
- group_by()
- mutate()
- count()
To facilitate these basic operations on tibbles, I created four macros with Keyboard Maestro. They all work similar. First I type the name of the tibble, then I start the macro by keystrokes
```{r}
new_data|
```
I type .-m which gives:
```{r}
new_data <- new_data %>% mutate(|)
```
| is the cursor
This is the macro
The macros for the other two operations are similar, with different endings:
.-g for group_by()
.-f for filter()
.-c for count()
I restricted all these macros to the use within RStudio.
I hope these resources are useful for your further studies. My next story will cover how I tried to shorten waiting times of outpatient operations. That analysis uses R and somewhat AI. You can find more stories about Rin my series Peter’s R here: kphahn57.medium.com
If you enjoy reading this and want to support my further writing, consider signing up as a Medium member. You’ll get full access to all stories on Medium. If you sign up using my link, I’ll earn a small commission.