When I first started coding in R, there was so much new stuff to learn it felt overwhelming. Although there were a lot of people excited to offer me advice, it was hard for me to know whether something was necessary, optional, or simply a personal preference. The following keyboard shortcuts are technically optional if you have no intention of using R long-term. However, if you want to move beyond early-noob-status, they go straight from optional to necessary.
1. Ctrl + Enter
This keyboard shortcut allows you to execute code within a script. It will either execute the line of code where your cursor lies or any code that’s highlighted. This lets you run code quickly without having to switch between the keyboard and mouse.
Tab is useful for auto-filling and code completion. You can use tab to either 1) prompt suggestions, or 2) select a suggestion. For example, if you type m and then tab, RStudio will offer several suggestions for auto-filling. To select a suggestion, simply hit tab again.
Tab can save you time typing while avoiding spelling mistakes in the process. If you’re prone to spelling errors, I highly suggest you utilize tab regularly.
If you’re working in the console, the up arrow will step through your history, line by line. So if you’ve executed a line of code in your console and you got an error, you don’t need to type the whole line out again. Just hit the up arrow and make the changes you need.
Bonus: fn + F1
This keyboard shortcut isn’t necessary, but it’s a good one! If you want to look at the R documentation for a function, you can always type ‘?function’ into the console. But if your cursor is on the function name, you can press fn + F1 to instantly bring up the documentation. Voíla! Easy access to function details at the click of two buttons.