R/add_pran.R

Defines functions add_pran

Documented in add_pran

#' Add Package to PRAN
#'
#' Automatically adds a package to PRAN or some other local repository
#'
#' @param pkg The package to use, can be a file path.
#' @param tar_path file path to tar. If no \code{tar_path} is given, defaults
#'   to package parent directory.
#' @param repo_path path to local repository to add package. If no repo path is given,
#'   defaults to PRAN path given by \code{pran_up}
#' @param build Build package before adding to PRAN.
#' @param remove Remove old versions from PRAN.
#' @export
#'
#' @examples
#'
#' \dontrun{
#' add_pran()
#' }
add_pran <- function(pkg = ".",
                     tar_path = NULL,
                     repo_path = NULL,
                     build = FALSE,
                     remove = FALSE) {

  pkg <- devtools::as.package(pkg)

  if (is.null(tar_path)) {
    tar_path <- dirname(pkg$path)
  }

  if (is.null(repo_path)) {
    repo_path <- pran_up()
  }

  if (build) {
    devtools::build()
  }

  miniCRAN::addLocalPackage(
    pkgs = pkg$package, pkgPath = tar_path, path = repo_path, type = "source",
    Rversion = R.version, writePACKAGES = TRUE,
    deps = FALSE, quiet = FALSE, build = FALSE
  )

  if (remove) {
    remove_pran(pkg$package)
  }

}
trekonom/devpran documentation built on Nov. 26, 2019, 12:16 a.m.