R/get_pkgs.R

Defines functions gksudor install_debs install_packages setup_jch

Documented in gksudor install_debs install_packages setup_jch

#' Setup jch misc
#'
#' Install DEBS and packages.
#' @export

setup_jch = function() {
  install_debs()
  install_packages()
}

#' Install packages
#'
#' Install multiple packages (unless already installed).
#' @export

install_packages = function() {
  data(pkgs)
  for (pkg in pkgs) {
    message(pkg)
    if (!require(pkg, character.only = TRUE))
      tryCatch(
        expr = install.packages(pkg),
        error = function(e) e$message
      )
  }
}

#' Install debs
#'
#' Install deb libraries
#' @export

install_debs = function() {
  data(debs)
  gksudor("apt-get install", debs, run = TRUE)
}

#' Use graphical sudo
#'
#' Call a command using gksudo
#' @param command Command to call (such as \code{"apt-get install"})
#' @param args Arguments
#' @param run Whether to also call the command (defaults to \code{TRUE})
#' @export

gksudor = function(command, args, run = TRUE) {
  command = paste(
    "gksudo",
    command, paste(args, collapse = " "),
    collapse = " ")
  if (run)
    system(command)
  else
    commmand
}
jchrom/jchmisc documentation built on May 17, 2017, 1:58 p.m.