Rstudio Hidden Gems

There's a bunch of features not very well known but a game changer in Rstudio. Sometimes these gems don't appear in documentation or in cheatsheets.

What's your hidden gem ?

My first addition to the topic:

Add a timestamp to your code chunk just type ts and then Shift + Tab

# Wed Feb 07 10:07:33 2018 ------------------------------

48 Likes

Reflow code with Ctrl + Shift + A

5 Likes

Yeah, a good one. But maybe it's not so hidden as it appears in Keyboard quick reference (Alt + Shift + K)

But one of my favourites anyway.

Thanks

1 Like

You can assign a shortcut for "Go To Next Chunk" in RMarkdown documents. I usually assign Ctrl + Down Arrow

4 Likes

The cheatsheet link under the Help tab makes me happy. Its not hidden but even so it took me a while to "discover" it.

1 Like

ctrl + . to find files or function.

6 Likes

Shift + Ctrl + r to insert a section heading or just a line to break up sections of code. Not a game changer really but saves you typing out a the # es

6 Likes

You can clear the screen by typing:

cat('\f')

on your console.

Ctrl l is even shorter for that (and l as in löschen is easy to remember if you happen to a German)

5 Likes

Or...CTRL+L
= "Control-Limpiar" (clear screen) in Spanish :slight_smile:

4 Likes

Nice! But why can't they format the date correctly? :smiling_imp:

4 Likes

This would be awesome if there is a shortcut for this one:

Jump cursor to different section headings in Rmarkdown.

Please tell me it exists.

1 Like

In R Markdown documents, you can use Ctrl + PageUp and Ctrl + PageDown to quickly jump to the previous and next section (including chunks).

You can also pop up the scope tree list using Shift + Alt + J (Ctrl + Shift + Alt + J on macOS).

30%20AM

12 Likes

Is there a hidden gem that allows me to type a comma outside of quotations?
When you type your first ", RStudio creates two marks right away, and your text goes in between. And so you type, let's say, c("foo"), and your cursor is currently between o and ". You need to place a comma after " to type the next argument, and my most common typo looks like this: c("foo," "bar")


Also, is there a hidden gem to indent / advance the code with TAB while inline? When I hit TAB inline, it's trying to bring up help or something, won't advance cursor.

1 Like

You can type the double quotes (") again when you are done and it will move you to the outside of the quotes so you can add the comma and keep typing. Typing the " after the last o in foo does not create another double quote, it only moves the cursor.

2 Likes

You can create you own. Add it to Global options > code > snippets

snippet comma
"${0}",

1 Like

Reflow code with Ctrl + Shift + A

I wish this worked with pipe chains!

Not sure if I would say it's hidden, (but I didn't see it for ages)

Find in Files
CTRL+SHIFT+F

Searches your whole code base for strings and then allows you to click to jump to them (like resharper for visual studio)


CTRL+ALT+SHIFT+M
Rename in scope
Ever had someone use a 1-letter variable name in 1500 lines of code? This lets you rename the actual variables called x not just replace each instance of x

13 Likes

Just recently found out that you can View() a data frame or package function within your script by CTRL+Left-clicking on their name.

4 Likes

Just recently found out that you can View() a data frame or package function within your script by CTRL+Left-clicking on their name.

I can't seem to figure out how to do this on Mac.... anyone?