R/remove_pran.R

Defines functions remove_pran

Documented in remove_pran

#' Remove old package versions
#'
#' Remove old package versions from PRAN.
#'
#' @param pkg package name
#' @param type source or binary (Default: \verb{source})
#' @param remove_all remove all(!!!) package versions (Default: \verb{FALSE})
#'
#' @export
#'
#' @examples
#'
#' \dontrun{
#' remove_pran("prognos.theme")
#' }
remove_pran <- function(pkg, type = "source", remove_all = FALSE) {
  # Package versions on PRAN
  pkg_versions <- miniCRAN::checkVersions(pkg, path = pran_up(), type = type)$source
  # Last time modified
  pkg_dates <- file.mtime(pkg_versions)

  pkg_info <- data.frame(file_name = pkg_versions, mdate = pkg_dates, stringsAsFactors = FALSE)
  # Sort versions by last time modified
  pkg_info <- pkg_info[order(pkg_info$mdate, decreasing = TRUE),]
  # Old versions
  if (remove_all) {
    old_versions <- pkg_info$file_name
  } else {
    old_versions <- pkg_info[-1,]$file_name
  }
  # Remove old versions
  file.remove(old_versions)
  # Update repo index
  miniCRAN::updateRepoIndex(pran_up(), type = c("source", "win.binary"))
}
trekonom/devpran documentation built on Nov. 26, 2019, 12:16 a.m.