1.4 Getting help
The best way to troubleshoot R errors is to copy-paste them into a search engine (e.g., Google). Searching online is also a great way to learn how to do new specific things or to find code examples. You should copy-paste solutions into your R script to then modify to match what you’re trying to do. We are constantly copying code from online forums and our own existing scripts.
However, there are many different ways to achieve the same thing in R.
Sometimes you’ll search for help and come across R code that looks nothing like what you’ve seen in this book.
The tidyverse packages are relatively new and use the pipe (%>%
), something we’ll come on to.
But search engines will often prioritise older results that use a more traditional approach.
So older solutions may come up at the top. Don’t get discouraged if you see R code that looks completely different to what you were expecting. Just keep scrolling down or clicking through different answers until you find something that looks a little bit more familiar.
If you’re working offline, then RStudio’s built in Help tab is useful.
To use the Help tab, click your cursor on something in your code (e.g., read_csv()
) and press F1.
This will show you the definition and some examples.
F1 can be hard to find on some keyboards, an alternative is to type, e.g., ?read_csv
.
This will also open the Help tab for this function.
However, the Help tab is only useful if you already know what you are looking for but can’t remember exactly how it works. For finding help on things you have not used before, it is best to Google it.
R has about 2 million users so someone somewhere has probably had the same question or problem.
RStudio also has a Help drop-down menu at the very top (same row where you find “File”, “Edit”, …).
The most notable things in the Help drop-down menu are the Cheatsheets.
These tightly packed two-pagers include many of the most useful functions from tidyverse
packages.
They are not particularly easy to learn from, but invaluable as an aide-mémoire.