diff --git a/NAMESPACE b/NAMESPACE index 9d4f93d..ebccd45 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -26,6 +26,7 @@ export(p_information) export(p_install) export(p_install_gh) export(p_install_version) +export(p_install_version_gh) export(p_inter) export(p_interactive) export(p_iscran) diff --git a/R/p_install_version_gh.R b/R/p_install_version_gh.R new file mode 100644 index 0000000..733dd91 --- /dev/null +++ b/R/p_install_version_gh.R @@ -0,0 +1,29 @@ +#' Install Minimal GitHub Package Version +#' +#' Install minimal GitHub package version(s). +#' +#' @param package \code{character} vector of the repository address(es) of the +#' package(s) you want to install a particular minimal version of. Repository +#' address(es) in the format \code{username/repo[/subdir][@@ref|#pull]}. +#' @param version Corresponding \code{character} vector of the minimal +#' package version(s). +#' @keywords version +#' @export +#' @examples +#' p_install_version_gh( +#' c("trinker/pacman", "hadley/testthat"), +#' c("0.2.0", "0.9.1") +#' ) +p_install_version_gh <- function (package, version){ + + ## Check that package and version are equal in length + if (length(package) != length(version)) { + stop("`packages` must be equal in length to `version`") + } + + # Version check on each of the packages + status <- Map(p_install_version_single_gh, package, version) + return(invisible(status)) + +} + diff --git a/R/p_install_version_single_gh.R b/R/p_install_version_single_gh.R new file mode 100644 index 0000000..3df4255 --- /dev/null +++ b/R/p_install_version_single_gh.R @@ -0,0 +1,32 @@ +## Helper single version of p_install_version +p_install_version_single_gh <- function(package, version, ...){ + + ## Determine if package is even in the users library + if (!basename(package) %in% p_lib()){ + out <- p_install_gh(package, ...) + if (isTRUE(out)) { + message(sprintf( + "\n%s not found in user's library; Version %s was installed", + basename(package), utils::packageVersion(basename(package))) + ) + } + return(invisible(out)) + } else { + + ## If package is not in user's library check if version ok + if (p_ver(basename(package)) < version) { + out <- p_install_gh(package, ...) + if (isTRUE(out)) { + message(sprintf("\n%s was updated to v. %s", + basename(package), utils::packageVersion(basename(package)))) + } + return(invisible(out)) + } else { + message(sprintf("\nVersion of %s (v. %s) is suitable", + basename(package), utils::packageVersion(basename(package)))) + return(invisible(TRUE)) + } + } + +} + diff --git a/README.md b/README.md index 0f33ca4..6dfb89d 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # pacman -[![Build Status](https://travis-ci.org/trinker/pacman.png?branch=master)](https://travis-ci.org/trinker/pacman) [![DOI](https://zenodo.org/badge/5398/trinker/pacman.svg)](http://dx.doi.org/10.5281/zenodo.15406) [![Version](https://img.shields.io/badge/Version-0.3.0-orange.svg)](https://img.shields.io/badge/Version-0.3.0-orange.svg) +[![Build Status](https://travis-ci.org/trinker/pacman.png?branch=master)](https://travis-ci.org/trinker/pacman) [![DOI](https://zenodo.org/badge/5398/trinker/pacman.svg)](http://dx.doi.org/10.5281/zenodo.15406) [![Version](https://img.shields.io/badge/Version-0.4.0-orange.svg)](https://img.shields.io/badge/Version-0.4.0-orange.svg) The [pacman](http://trinker.github.io/pacman_dev/) package is an R package management tool that combines the functionality of base library related functions into intuitively named functions. This package is ideally added to .Rprofile to increase workflow by reducing time recalling obscurely named functions, reducing code and integrating functionality of base functions to simultaneously perform multiple actions. diff --git a/inst/CITATION b/inst/CITATION index bc12fe6..4e74cb1 100644 --- a/inst/CITATION +++ b/inst/CITATION @@ -2,14 +2,14 @@ citHeader("To cite pacman in publications, please use:") citEntry(entry = "manual", - title = "{pacman}: {P}ackage Management for R", + title = "{pacman}: {P}ackage Management for {R}", author = "Tyler W. Rinker and Dason Kurkiewicz", organization = "University at Buffalo/SUNY", address = "Buffalo, New York", note = "version 0.4.0", - year = "2013", + year = "2015", url = "http://github.com/trinker/pacman", - textVersion = paste("Rinker, T. W. & Kurkiewicz, D. (2013).", + textVersion = paste("Rinker, T. W. & Kurkiewicz, D. (2015).", "pacman: Package Management for R.", "version 0.4.0. University at Buffalo. Buffalo, New York.", "http://github.com/trinker/pacman") diff --git a/inst/build.R b/inst/build.R index b6cdc97..4455b16 100644 --- a/inst/build.R +++ b/inst/build.R @@ -1,20 +1,22 @@ +root <- Sys.getenv("USERPROFILE") +repo <- pack <- basename(getwd()) + curd <- getwd() -usr <- dirname(path.expand("~")) -loc <- file.path(usr, "Desktop") +loc <- file.path(root, "Desktop") setwd(loc) -qman <- function(x = "pacman", db = file.path(usr, "Dropbox/Public"), dir=loc) { +base.git <- dirname(curd) + +qman <- function(x = repo, db = file.path(root, "/Dropbox/Public"), dir=loc) { path <- file.path(dir, paste0(x, ".pdf")) - if (!file.exists(path)) stop(paste(x, "does not exist...")) + if (!file.exists(path)) stop(paste(x, "does not exist...")) opath <- file.path(db, paste0(x, ".pdf")) file.copy(path, opath, overwrite = TRUE) message("manual copied!\n") } -repo <- pack <- "pacman" -base.git = file.path(usr, "GitHub") -quick = TRUE +quick <- TRUE library(devtools) unlink(paste0(pack, ".pdf"), recursive = TRUE, force = TRUE) @@ -28,5 +30,4 @@ system(paste(shQuote(file.path(R.home("bin"), "R")), qman(repo, dir=loc) setwd(curd) -message("Done!") - +message("Done!") \ No newline at end of file diff --git a/man/p_install_version_gh.Rd b/man/p_install_version_gh.Rd new file mode 100644 index 0000000..6344484 --- /dev/null +++ b/man/p_install_version_gh.Rd @@ -0,0 +1,27 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/p_install_version_gh.R +\name{p_install_version_gh} +\alias{p_install_version_gh} +\title{Install Minimal GitHub Package Version} +\usage{ +p_install_version_gh(package, version) +} +\arguments{ +\item{package}{\code{character} vector of the repository address(es) of the +package(s) you want to install a particular minimal version of. Repository +address(es) in the format \code{username/repo[/subdir][@ref|#pull]}.} + +\item{version}{Corresponding \code{character} vector of the minimal +package version(s).} +} +\description{ +Install minimal GitHub package version(s). +} +\examples{ +p_install_version_gh( + c("trinker/pacman", "hadley/testthat"), + c("0.2.0", "0.9.1") +) +} +\keyword{version} + diff --git a/tests/testthat/test-p_install.R b/tests/testthat/test-p_install.R index 45b6ec4..5f6fb86 100644 --- a/tests/testthat/test-p_install.R +++ b/tests/testthat/test-p_install.R @@ -1,8 +1,10 @@ context("Checking p_install") test_that("p_install works",{ + skip_on_cran() + skip_on_travis() require(pacman) expect_warning(p_install("iDontExistAnywhere")) tmp <- suppressWarnings(p_install("iDontExistAnywhere")) expect_false(tmp) -}) \ No newline at end of file +})