Created
January 23, 2012 14:35
-
-
Save aL3xa/1663426 to your computer and use it in GitHub Desktop.
Build, Check, Install and (Re)Load R Package
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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