create R packages? 3. Steps to creating a R package 4. Hands-on Session to create a simple R package 5. Deploying R packages to CRAN, GitHub & Bioconductor
as a collection of commonly-utilised functions/modules which allow a user to directly assimilate these functions in an R script. • Packages created in R may be uploaded into GitHub, CRAN, or Bioconductor. • Subsequently, these packages may be downloaded by other R users, and used in the R console (CLI) or R-Studio (GUI).
functions/tasks/pipelines into a single module which simplifies data analysis (especially for repeat workflows). • Packages created in R may be shared with other R users, via uploading into GitHub, CRAN or Bioconductor. • Updates in deployed packages can be easily & quickly reflected in all user installations of the said package by simply calling the Update packages / Update function within R / RStudio respectively.
i. Install & load the following packages in R: a. roxygen2 & b. devtools ii. Create a package directory to save your .R files into & set the working directory to the created package directory. iii. Create a .R file containing the functions for the package & save it in the created package R directory. iv. Add comments at the beginning of the created function in the .R script. v. Create the documentation using the document() function. vi. Set the working directory to the parent directory of the created package & use the install() function to install the newly-created package. vii. Test the function/(s) in the newly-created & installed package. viii. *Upload the created package into CRAN/GitHub (optional).
i. Click on New Project > New Directory > R Package. ii. Specify the package name & click the Add button to add the package source files. a. You need to have created the package source files first. iii. Click on Create Project to create the R package. iv. Go through the steps in 3. A) as indicated in the previous slide.
i. Create a stat_pkg.R file within parentdir/R as follows: #' A Simple Statistical Package #' #' This package allows you to calculate the mean, median & standard deviation of a sample dataset. #' @param x numeric vector. #' @keywords stat_pkg #' @export #' @examples #' stat_pkg(x) stat_pkg <- function(x){ mu <- mean(x); med <- median(x); std <- sd(x); cat("Mean = ", mu, "\n", "Median = ", med, "\n", "Standard deviation = ", std, "\n"); }
following URLs: i. https://cran.r-project.org/web/packages/policies.html (*Important - Policies on deploying CRAN packages) ii. https://cran.r-project.org/submit.html (the actual site to upload packages for submission into CRAN) For GitHub deployment, refer to the following URL: i. http://kbroman.org/github_tutorial/pages/init.html (for instructions on GitHub repository creation & deployment) For Bioconductor deployment, refer to the following URL: i. https://bioconductor.org/developers/package-submission/ (for instructions on package submission to Bioconductor)