Chapter 5 Learning R
What is the best way of learning R without losing motivation or feeling discouraged? This chapter covers four learning strategies, a mindset, and how you can ask others for help and where to find other R users.
5.1 Learning strategies
Here is a selection of different learning strategies, that can be combined or applied on their own. The basic idea is to have exposure to the language, similarly as you do when you learn a natural language.
Learn with isolated & digestible examples
First, make sure to not overwhelm yourself by trying to learn everything at once. It is better to stick to isolated examples. For example, instead of trying to tackle the whole data analysis workflow all at once, try to become better at data reshaping first. And instead of using your own data, with which you might first struggle to import into R, use the dataset that R already provides1.
Look for a steady stream of data or exercises
Such a weekly data stream is TidyTuesday run by the R for Data Science online learning community. TidyTuesday data supply was created to have “toy” data to practice data visualization and basic data wrangling in R.
Since their start in 2018 they now have over 70 datasets2. These datasets are “tamed”, but not always tidy.
Watch out for an upcoming code puzzle initiative similar to advent of code by Irene Steves.
Watch recordings
Many small & large R conferences record their speakers:
- New York R conference recordings
- useR! conference recordings
- RStudio conference recordings
rOpenSci has monthly community calls.
Some R users record their R usage with screencasts, for example:
Read blog posts
The best resource for new blog posts or any other R news is Rweekly, a community-driven initiative that provides a curated weekly newsletter.
5.2 Embrace imperfection
Learning a programming language can be discouraging. Things might not work from start, and it will constantly feel like everyone else is more proficient and ahead of you.
Keep in mind that there is no such thing as a perfect R-script. Of course, there are best-practices, but writing an R-script will always be an iterative process, where you start and after some weeks you might have learned something, and you want to replace your old code with an improved version.
Another reason to not strive for perfection is that R offers a variety of solutions for one problem. For example, there are many different ways to import data into R, or to subset your data. Therefore it is likely that your R-scripts will look different from any of your colleagues.
Instead of feeling discouraged, you should embrace imperfection and take it as a driving force to learn more.
Exploit imperfection
You can exploit imperfection in three ways:
Look & review each others code: Ask your colleagues at work if they would like to spend 30 minutes looking at your code. In return, you can do the same for them. This will not only give you (and them) insight into how other people write R code but also force you to produce reproducible R-script (otherwise your colleague will not be able to run your code).
Rewrite your code: You will constantly improve your R skills. Do not hesitate to rewrite your own R code (while keeping the output the same). This ideally goes hand in hand with unit tests.
Look at open source code: Watch out for public repositories (for example this one). This is another great way to see how others write R scripts and how they make sure that their repository is reproducible. See also screencasts mentioned earlier.
5.3 How to ask for help
What do you do if you have a question? For example, you get an error message, something is not working as intended or you simply want to know if there is any other possibility?
There are three steps you should keep in mind3:
- Browse the web first
- Create a reproducible example
- Post your question online
Look online
First, scan the web by simply copy and paste the error message. This will most likely direct you to the following two websites:
Sometimes your question or error message is too specific, and you might want to describe the problem in words when searching.
Create a reproducible example
If you cannot find any existing solution to your problem, you can post your question online4. To increase the likelihood of getting an answer and feedback, you should provide a reproducible example. Here is the workflow of doing this:
First, you try to reproduce the error message with a dataset within R, e.g. the iris
dataset. The iris
dataset is relatively small and contains a mixture of numeric and factor variables. This is a good dataset for many use cases.
Very often, working out a small example will already solve your problem. Solely, by thinking about the problem, you will find the solution yourself.
If not, install the reprex
package. Then highlight the code of your reproducible example, choose in the Addins
Reprex selection (see video here).
Ask on your question online
Once you have your reproducible example, post it in one of the following places:
Ask within an online community. This is a good place to start because the space is protected through a Code of Conduct and because others in the community are learners too (hence, can put themselves into your shoes).
Ask the RStudio community.
Ask on Stack Overflow.
Ask on twitter using the
#rstats
hashtag.
5.4 Become part of the community
Sometimes it feels as if the R community is one big family with different, overlapping communities.
R-Ladies
R-Ladies is a worldwide organisation to promote gender diversity in the R community.
As a diversity initiative5, the mission of R-Ladies is to achieve proportionate representation by encouraging, inspiring, and empowering people of genders currently underrepresented in the R community.
At the moment, there are 167 R-Ladies chapters (local R user groups) in 47 countries.
R-Ladies has a Code of Conduct that ensures that R-Ladies meetups and online spaces are safe places.
For women and gender minorities R-Ladies offers:
Join an online community
R for Data Science online learning community has a Slack, is on Twitter: @ r4dscommunity and provides the weekly TidyTuesday datasets.
French-speaking r-grrr Slack (+ online ressources)
rOpenSci
rOpenSci fosters a culture that values open and reproducible research using shared data and reusable software.
The non-profit initiative founded in 2011 builds software with a community of users and developers and educates scientists about transparent research practices.
A good place to get familiar with rOpenSci is, to attend or re-watch a community call (archive). You can also contribute via the shinyapp.
Join an R meetup
R meetups and R user groups are great places to meet other people and to exchange knowledge!
There are several R meetups in the lemanic region:
If you are a woman or gender minority and work remotely or are in another sense “remote”, there is R-Ladies Remote (coffee chats, journal club).
You can find the full list of RUG’s here and for R-Ladies here.
Write blog posts
Writing blog posts can be a fun way of learning R. For example, to start, you could document your journey of learning R.
Even if you do not have a blog, you can start with gist.github.com and later move to blogdown
.
Do not forget to submit your blogpost to rweekly!
Engage on Twitter
Twitter is a fun place to see new R features and learn about R. Here are four fun handles to follow:
Type
data()
into the console to see “in-house” data in R.↩See also this Shinyapp and this podcast.↩
Maëlle Salmon wrote a great blog post about Where to get help with your R question?.↩
It is important to make your question public to everyone, so others will be able to look up the solution later.↩
RForwards is another initiative to increase participation of women and other under-represented groups in the R community.↩