author: Lee F Richardson date: Jan 30, 2018
All code online at: https://github.com/leerichardson/leeR
"The Comprehensive R Archive Network (CRAN) is a collection of sites which carry identical material, consisting of the R distribution(s), the contributed extensions, documentation for R, and binaries." - CRAN servers all over the world, called mirrors - CRAN mirrors have contributed extensions (R-packages)
- Authenticity
Quality Control (external standards/checks)
More likely to be used (install.packages
)
- CRAN and Github: Platforms for sharing R packages
CRAN more reliable, takes more effort
Github easy, no external checks
Choice depends on project
R CMD check
: Terminal command, checks package
Runs a series of checks on package
Run in console with the devtools
package:
devtools::check()
devtools::check()
also:
- Runs documentation, builds package (R CMD build
)
R CMD check
gives three types of feedback:
- Errors: Most Severe
- Warnings: Medium Severe
- Notes: Least Severe
Details on each check: 1.3.1 Writing R Extensions
Say we add a new test to our package:
test_that("our function works", {
expect_equal(2, 2)
expect_equal(1, 2)
})
What will devtools::check()
do?
#' Print a string!
#'
#' @param string to print
#' @param fake parameter
#'
#' @return A printed string
#' @examples
#' to_print <- "Hello, world!
#' leeR_demo(to_print)
#'
leeR_demo <- function(string) {
print(string)
}
devtools::check()
?
#' Multivariate normal random numbers
#'
#' @param n number of observations
#' @param mean_vec vector of means
#'
#' @return n x length(mean_vec) of
#' observations from a multivariate normal
generate_mvnorm <- function(n, mean_vec) {
rmvnorm(n = n, x = mean_vec)
}
devtools::check()
...
devtools::use_package("mvtnorm")
mvtnorm::rmvnorm
- Remember to keep running R CMD check
Solve with Continuous Integration and Win-builder!
What is Continuous Integration (CI)?
"Continuous Integration is the practice of merging in small code changes frequently - rather than merging in a large change at the end of a development cycle. The goal is to build healthier software by developing and testing in smaller increments. This is where Travis CI comes in." - https://docs.travis-ci.com/user/for-beginners - Travis is a "Continuous Integration" (CI) service
R CMD check
on every Github push- Add to package with:
devtools::use_travis("/home/lee/Dropbox/leeR")
Creates .travis.yml
in source directory
Get Travis account, link Github account
Push to Github
E-mail will tell you if it passed
- Travis checks package on Ubuntu
devtools::build_win()
Build, submits to https://win-builder.r-project.org/
E-mail in 30-60 minutes with results
R CMD check
passesOnce these steps are complete: - Follow http://r-pkgs.had.co.nz/release.html#release-check - Aim, aim, Let it fly!
devtools::release()
Submits this form https://cran.r-project.org/submit.html
It all comes down to R CMD check
Know goals, prepare early for CRAN
Travis, winbuilder are useful external tools
Big victory for the devtools/R-packages book
Two good lists of all the checks are - http://r-pkgs.had.co.nz/check.html - Section 1.3.1 of Writing R Extensions
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.