Get startedGet started for free

Package build

1. Package build

In this video, we add another function to our package and load all files to ensure functionality before installing. Additionally, we programmatically verify that our package meets the requirements of R packages.

2. Time unit converter

We will add an additional function to our package that converts time between hours, minutes, and seconds.

3. Use time_converter() and add to package directory

To test use of the function, we specify 24 hours with an output in seconds. This gives eighty six thousand four hundred seconds. To add our new function to the R directory, we send the function definition for time_converter to its own file with the base R dump function. As before the function name is the first argument and we are sending it to a file in the R directory with that same name.

4. Load all files in the package

Before installing a package in the development phase, it can be helpful to load all the package files into the current working environment. This can be done by calling load_all from the devtools package. It loads all the R files in our unitConverter package into the current R session, allowing us to test and debug our package's functions prior to installation. It helps ensure that our package's code is working correctly and that there are no syntax errors or other issues.

5. Silly typo

Suppose we accidentally forgot to close out one of our last curly brackets in our time converter code as shown in the time_converter dot-R file we just dumped.

6. Detecting errors with load_all()

Running the load_all function again, now gives us an error that we can track down. This unexpected end of input error often refers to a missing curly brace. We could add it back to line 15 and we'd get the clean output seen previously before the typo.

7. Differences between load_all() and install()

load_all is primarily used during package development and testing. It loads the package and its dependencies into the current R session, allowing us to work with the package and test its functionality without needing installation. install is used to install a package and its dependencies usually after using load_all. This function is typically used when we want to install a package for the first time or update an existing package to a newer version.

8. Check package requirements programmatically

The devtools check function performs a series of checks and validations on an R package to ensure its quality, correctness, and adherence to package development standards. It goes through a comprehensive set of tests and checks, including syntax checks, package dependencies, documentation quality, coding standards, and more. By running check, package developers can identify potential issues, errors, or inconsistencies in their package code and documentation before sharing it with others. This function is a crucial step in the package development workflow as it helps ensure that the package meets the requirements and standards set by the R community and enhances its overall reliability and usability.

9. Some check() output

Its output can be quite lengthy due to the number of checks that it runs. We'll return to this function later in the course after documenting further. Ultimately, the focus should be on the last line of output as a starting point. If there are X's shown, it is recommended to look further into the longer output. Getting to no errors, warnings, or notes is ideally where to get our package. Errors are notable problems that must be resolved before the package can be deemed satisfactory. Warnings draw attention to possible concerns or violations of recommended practices. Notes provide suggestions for enhancements, such as the inclusion of supplementary documentation.

10. Let's practice!

Try it out in the following exercises.

Create Your Free Account

or

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