R/drat-lib-pkgs.R

#' drat insert
#'
#' Insert packages into a local drat repo from either a library or a pkgs.yaml file.
#'
#' @param path(string) Path to library or pkgs.yaml file respectively.
#'
#' @name drat_insert
NULL


#' @rdname drat_insert
#' @export
drat_insert_lib <- function(path, commit = TRUE) {
  warn("This function is currently experimental!")

  pkgs <- lapply(read_dcfs(path), function(pkg) {
    list(name = pkg$Package, version = pkg$Version)
  })
  drat_insert_impl(pkgs, commit)
}


#' @rdname drat_insert
#' @export
drat_insert_pkgs <- function(path, commit = TRUE) {
  warn("This function is currently experimental!")

  pkgs <- yaml::yaml.load_file(path)[["packages"]]
  drat_insert_impl(pkgs, commit)
}


drat_insert_impl <- function(pkgs, commit) {
  if (!is.local_drat_repo_set()) {
    error(
      "local drat repo has not been set. Use the function: ",
      "set_local_drat_repo() to do so."
    )
  }

  for (pkg in pkgs) {
    # FIXME: this function has gone missing?!
    download_and_insert(pkg$name, pkg$version, commit)
  }
}
Mullefa/locallib documentation built on May 7, 2019, 5:12 p.m.