Keyboard and R Studio Shortcuts and Tips
Keyboard shortcuts for Mac/Windows computers
- command c (copy)
- command x (cut)
- command v (paste)
- command a (select all)
- command left/right/top/bottom (jump to the start/end of a line or top/bottom of a page)
- command shift left/right/top/bottom (highlight a whole line/page)
- option left/right (jump to the previous/next word)
- command s (save file)
- command o (open file)
- command z (undo - do twice to undo last change and the change before that etc)
- command f (find)
Keyboard shortcuts for R Studio
- command enter (run current line of code)
- double click on a word to highlight
- # (option 3 on mac) for comment or cmd shift c to comment/uncomment (ctrl shift c on windows)
- control L (in console to clear console)
- option - (assignment arrow) or Alt - on Windows
- command shift m (pipe operator) or ctrl shift m on Windows
- option shift k (view keyboard shortcuts list) or alt shift k for windows
Tips for getting started with learning R
- Write down every new R command you learn onto your own personal "cheat sheet" so you have a single document containing all the commands for when you inevitably forget (we ALL forget and have to look up things again and again - it's normal - and its much faster if you have all the commands there in a handy document with your own notes on about what they do and when to use them etc).
- The whole line/command is run regardless of where your cursor is on the line when you run the code.
- Write code in sequence. Sequence matters.
- Write a comment above every line of code to remind yourself what it does.
- Add space between commands (i.e. a line with no text between each command) to make it easier to see when a command ends (as some commands run on multiple lines).
- If a function has lots of parameters (the settings inside the brackets that are separated by commas) it makes the line of code really long and can make it difficult to read so it can be useful to press return after each comma so parameters are listed vertically rather than horizontally
- Make sure you understand every line of code and every parameter that you've used inside the brackets of a function. A few seconds/minutes properly understanding each command will be a big investment for future work. If you don't understand what a command is doing, google it or use RStudio's help feature
- Play around with different parameter values and learn about other parameters that are available for each function. Every package and every function will have at least one page on the internet that describes what it does and the options available and often there are plenty of YouTube video tutorials too.
- It can be helpful to practice using a small dataset that you've created yourself so you know what you're expecting to happen after you run some code on it, and if it's different, you can spot it and try to understand why it's different to what you were expecting. This can be particularly helpful with the data wrangling/re-shaping we do with dplyr. For example, you might create a csv file with just a handful of rows and columns of data that you've made up, import it into your Rstudio session, and play around with filtering, selecting etc. It can help with visualising what each function is doing.
- Just had an error and figured out how to fix it? Make a note of the error and what you did to fix it. When you get an error next time, it might help.
- Practice as much as you can each week and keep all your code. You'll thank yourself in the future.
See more learning materials