DataCamp Blog, and kindly contributed to Want to share your content on R-bloggers? [This article was first published on, and kindly contributed to R-bloggers ]. (You can report issue about the content on this page here Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Learn from the creator of ggplot2, dplyr, and more! Whether you’re a seasoned veteran or R novice, DataCamp’s latest course will help you make your code more readable, avoid coding errors, and automate repetitive tasks.

Start For Free

Like all DataCamp courses, Writing Functions in R is self-paced and combines high-quality video, in-browser coding, and gamification to make your learning experience fun.

What you’ll learn

Hadley & Charlotte will teach you the fundamentals of writing functions in R so that, among other things, you can make your code more readable, avoid coding errors, and automate repetitive tasks.

In the first chapter, you’ll review the syntax of writing a function in R, the basic data types in R, subsetting and writing for loops. [Start First Chapter For Free] Next, we focus on when it makes sense to write a function, how to get started and what to keep in mind when you are writing your own functions.

In the third chapter, you’ll learn how to use the map functions in the purrr package. This will enable you to solve new iteration problems with greater ease. The fourth chapter takes your understanding of purrr one step further and illustrates how to deal with functions that might return an error, how to iterate over multiple arguments and how to iterate over functions that have no output at all. The final chapter is about writing functions that don’t surprise you or your users. Learn which functions you should avoid using inside of a function and which you should use with care.

Start For Free