Building your own 'R PACKAGE' and 'DESCRIPTION' file
A package in R is a standardized and structured unit that comprises various components, including
1. R code
2. Documentation
3. Data
4. External code
Creating a package is initiated by generating a new blank project in R.
Installing 'devtools' and 'roxygen' which help in creating packages and can be done by the following code:
install.packages(“devtools”)
install.packages(“roxygen2”)
library(devtools)
library(roxygen2)
package.skeleton()
It can also be installed directly by implementing code
devtools::install_github("hadley/devtools")
It creates new files:
- Data, folder
- DESCRIPTION, information file
- Man, help folder
- R folder contains the . R files for functions
- And “read-and-delete-me” file
The Description consists of fundamental information regarding the package in the following sequence: The important and required fields are ‘Package’, ‘Version’, ‘License’, ‘Description’, ‘Title’, ‘Author’, and ‘Maintainer’, the remaining fields (Date, Suggests, ...) are optional.
The Package and Version fields give the name and the version of the package, respectively. The name should consist of letters, numbers, and the dot character and start with a letter.
The version is a sequence of at least two (and usually three) non-negative integers separated by single dots or dashes.
The Title should be no more than 65 characters, because it will be used in various package listings with one line per package.
The Author field can contain any number of authors in free text format,
the Maintainer field should contain only one name plus a valid email address (similar to the “corresponding author” of a paper). The Description field can be of arbitrary length.
Building Package:
It is important to save the code and description accurately.
R file code:
Build tab and check -allows error checking and building.
Roxygen-documentation set up
- In the build tab, configure build tools is selected followed by turning on the generate documentation with roxygen.
- later in roxygen options, all options are turned on.
- It is important to start the code file with #’ which documents the code using the oxygen package followed by build, check and reload.
Comments
Post a Comment