1. Learn
  2. /
  3. Courses
  4. /
  5. Creating R Packages

Exercise

Including functions in a package

Once you have written your function code you need to save it in the R directory of your package. Typically you can do that by saving an R script in the usual manner (i.e. "Save As").

In the instance that you already have objects created, as you did in the last exercise, that you want to write to the R directory you can do this programmatically. You can use the function dump() to send a named R function to a particular file. The two arguments that you need to pass to this function are the name of the R object, as a character string, and the path to the file that you want to create, including the extension .R.

The package datasummary has already been created, along with the function numeric_summary() and is available in your workspace.

Instructions

100 XP
  • Use the dir() function again to see what is currently available in the R directory of datasummary.
  • Using the dump() function, write the numeric_summary() function to the R directory, saving the file as numeric_summary.R.
  • Print the contents of the R directory again.