Ari Lamstein

Request for Resources: Teaching Computer Science Basics to R Programmers

One of the most enjoyable parts of my job is teaching R to our incoming analysts. These analysts are largely recent college graduates with a limited background in computer science and statistics. Historically my job has been to teach them the basics of the Tidyverse over 3 half-days. I’m writing today to see if anyone can recommend some resources to help me with a new, specific teaching goal I have for this workshop: Computer Science basics.

The workshop I give is largely based on Garrett Grolemund’s workshop “Mastering the Tidyverse”. Back when I was self employed I got certified by RStudio to teach the Tidyverse. This primarily consisted of attending Garrett’s “train the trainer” workshop on pedagogy and being evaluated on a small lesson I created myself. As a bonus I was pointed to the slides Garrett created for when he teaches the Tidyverse himself (link). Those slides were an order of magnitude better than what I was using before. And while I wound up tweaking them slightly, they are still the basis of my current workshop.

Now that my company is largely proficient in the Tidyverse, I have a new teaching goal. In addition to teaching the incoming analysts the Tidyverse, I would like my company to become more proficient at the basics of Computer Science. Concretely, in this context, that means having people change their approach to what it means to code in R. Instead of “just” writing code to solve the problem in front of them, I’d like people to start thinking about writing code that can be reused across multiple projects. This means converting their scripts to generalized functions (and, eventually, putting them into our internal packages). In order to do this, they need to learn the basics of Computer Science: writing functions, using conditionals, and understanding things like variable scope and iteration.

If anyone knows of some open source slides or exercises for this, please let me know in the comments below. In the mindset of sharing, here are some exercises I improvised recently while mentoring a new analyst 1-1 who needed to learn the basics of writing functions:

  • Write a function that greets you by name:
    • Start with something hard-coded: print(“Hi Bob”)
    • Modify to take the name as an argument
    • Add a default parameter
  • If statements:
    • %% operator
    • Function to print if a number is even or odd
  • Back to the “Hi Bob” function:
    • Take a second parameter “time_of_day”
    • If “morning” print “Good morning <name>”, etc.
    • ?stop if time_of_day is not valid
  • An exercise I did not include in this mentoring sessions, but which I was thinking of including in the future training, is to create a function my_summary that basically reimplements the summary function (print the min, max, mean of a vector of numbers). This would show the value in not needing to copy-paste a multi-step process.

When I mentioned this to a Manager at my company she commented that these lessons did not include either variable scope (which confuses some of her analysts) or the debugger (which her analysts do not know about). To me this underscored the potential value in finding a good existing workshop on these topics – as someone who has been a software engineer for most of his career, it’s hard to remember what all the basics are, let alone the best way to introduce them!

When I mentioned these lessons to a friend who teaches Python professionally, he said that he often has students write a function that counts the number of vowels in a string. I like this exercise. It would require me to teach for loops which, even though they are not as widely used in R as other languages, are helpful in learning to think algorithmically.

Please use the comments (or my Contact page) to share links to any sharable resources you know of that relate to teaching these topics in R. Thanks!

Ari Lamstein

Ari Lamstein

I currently work as a Staff Data Science Engineer at a marketing analytics consultancy. I have 20 years experience developing software in areas such as data science, web development and video games. I have also worked as a technical trainer and independent consultant.

Thanks for visiting!

Sign up to stay up to date with the latest blog posts: