Skip to content

Instantly share code, notes, and snippets.

@aL3xa
Created January 23, 2012 14:35
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save aL3xa/1663426 to your computer and use it in GitHub Desktop.
Build, Check, Install and (Re)Load R Package
b <- function(path = "package/", ...){
require(devtools)
require(roxygen2)
pkg <- as.package(path) # package pointer
## update documentation
message("Updating documentation...")
roxygenise(path, ...)
## build package
message("Building package...")
bld.path <- build(pkg)
## check package
message('Running "R CMD check"...')
system(sprintf("R CMD check %s", bld.path))
## install package
message('Installing package...')
pkg.info <- devtools:::load_pkg_description(path)
pkg.name <- pkg.info$package
pkg.targz <- sprintf("%s_%s.tar.gz", pkg.name, pkg.info$version)
install.packages(pkg.targz, repos = NULL, type = "source")
message("Package was successfully built and installed!")
## detach package if already attached (loaded in search path)
pkg.ns <- sprintf("package:%s", pkg.name)
if (pkg.ns %in% search())
detach(pkg.ns)
## load package
library(pkg.name)
message("Package (re)loaded!")
invisible(TRUE)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment