Custom Packages
Building your own packages is a good idea if you want to share code or data with other people, or if you just want to pack it up in a form that’s easy to reuse, you should consider building your own package. This section explains the easy way to create your own packages.
Creating a Package Directory
To build a package, you need to place all of the package files
(code, data, documentation, etc.) inside a single directory. You can
create an appropriate directory structure using the R function
package.skeleton:
package.skeleton(name = "anRpackage", list,
environment = .GlobalEnv,
path = ".", force = FALSE, namespace = FALSE,
code_files = character())This function can also copy a set of R objects into that
directory. Here’s a description of the arguments to package.skeleton.
| Argument | Description | Default |
|---|---|---|
| name | A character value specifying a name for the new package | “anRpackage” (as a side note, this may be the least useful default value for any R function) |
| list | A character vector containing names of R objects to add to the package | |
| environment | The environment in which to evaluate list | .GlobalEnv |
| path | A character vector specifying the path in the file system | “.” |
| force | A Boolean value specifying whether to overwrite
files, if a directory name already exists at path | FALSE |
| namespace | A Boolean value specifying whether to add a namespace to the package | FALSE |
| code_files | A character vector specifying the paths of files containing R code | character() |
For this book, I created a package called nutshell containing ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access