I'm using RStudio
and normally run my code line by line, using Crtl + Enter. In general this works fine but working dplyr
I would like to run a whole code-section I wrote using the pipe-operator %>%
,
For e.g. I'd like to execute the following code-section at once, at the best independently from the current cursor position within the piped codelines:
mtcars %>%
filter(carb >= 2) %>%
group_by(cyl) %>%
summarise(mean.hp = mean(hp))
I could run this line by line or mark all lines and then press Crtl + Enter but both ways are some kind of annoying. Searching the internet and the RStudio-options available in "Tools/Modify Keyboard Shortcuts
" I only found other options like running a whole section, that is starting at
# Example section--------------------
Execute code: The 2 shortcuts that I use most often to run the code are Ctrl+Enter and Ctrl+Alt+R. Ctrl+Enter is used when executing the code line by line. Also, a highlighted chunk of code can also be executed by this command. If you are looking to run the complete code, then Ctrl+Alt+R should be used.
Place cursor anywhere in the code chunk and use Crtl + Shift + ↑ (hold down Crtl and Shift, then push ↑ button). The first time the word in which the cursor is placed gets highlighted, then, when repeted, the whole chunk of code gets highlighted. If you have a nested loop or another nested structure this will highlight the whole innermost loop, then the second inner most loop etc.
When you have the code highlighted you can press Crtl + Enter to execute the code.
I use the sections feature of RStudio liberally (like you noted) - but you didn't mention the keyboard shortcut Ctrl+Alt+T to run the section (all the code between # comment ---- or #### partitions).
# mutate ----
# rename ####
# filter ####
# summarize ####
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With