Skip to main content
Paul Love avatar

Paul Love has completed

Creating R Packages

Start course For Free
4 hours
4,200 XP
Statement of Accomplishment Badge

Loved by learners at thousands of companies

Course Description

In this course, you will learn the end-to-end process for creating an R package from scratch. You will start off by creating the basic structure for your package, and adding in important details like functions and metadata. Once the basic components of your package are in place, you will learn about how to document your package, and why this is important for creating quality packages that other people - as well as your future self - can use with ease. Once you have created the components of your package, you will learn how to test they work properly, by creating tests, running checks, and building your package. By the end of this course you can expect to have all the necessary skills to create and share your own R packages.
For Business

GroupTraining 2 or more people?

Get your team access to the full DataCamp library, with centralized reporting, assignments, projects and more
Try DataCamp for BusinessFor a bespoke solution book a demo.
  1. 1

    The R Package Structure


    In this chapter, you will learn the basics of creating an R package. You will learn about the structure of R packages, set up a package, and write a function and include it in your package. You will also learn about the metadata stored in the DESCRIPTION and NAMESPACE files.

    Play Chapter Now
    Introduction to package building
    50 xp
    The structure of an R package
    100 xp
    Contents of an R package
    50 xp
    Writing a simple function
    100 xp
    Including functions in a package
    100 xp
    50 xp
    Package names
    50 xp
    Writing a DESCRIPTION file
    50 xp
    Detailing authors, maintainers and contributors
    50 xp
    Optional directories
    50 xp
    The use_* functions
    100 xp
    Best practice for structuring code
    100 xp
  2. 2

    Documenting Packages

    In this chapter, you will learn how to document your package. You will learn why documentation is important, and how to provide documentation for your package, its functions, and other components. You will also learn about what it means to export a function and how to implement this in your package.

    Play Chapter Now
  3. 3

    Checking and Building R Packages

    In this chapter, you will learn about how to run checks to ensure that your R package is correctly structured and can be installed. You will learn how to correct common problems, and get your package ready to be built so it can be shared with others.

    Play Chapter Now
  4. 4

    Adding Unit Tests to R Packages

    In the final chapter, you will learn how to add tests to your package to ensure your code runs as expected if the package is updated or changes. You will look at how to test functions to ensure they produce expected values, and also how to test for other aspects of functionality such as expected errors. Once you've written tests for your functions, you'll finally learn how to run your tests and what to do in the case of a failing test.

    Play Chapter Now


Collaborator's avatar
Sumedh Panchadhar
Collaborator's avatar
Eunkyung Park
Collaborator's avatar
Richie Cotton


Introduction to Writing Functions in R
Aimee Gott HeadshotAimee Gott

Head of Skill Assessment Content at DataCamp

See More

Join over 13 million learners and start Creating R Packages today!

Create Your Free Account



By continuing, you accept our Terms of Use, our Privacy Policy and that your data is stored in the USA.