R/execs.R

Defines functions pip_exec python_exec npm_exec node_exec libreoffice_exec chrome_exec get_chrome_version

Documented in chrome_exec libreoffice_exec node_exec npm_exec pip_exec python_exec

get_chrome_version <- function(chrome_dir) {
  if(is_osx()){
    file_exe <- "Google Chrome"
  } else {
    file_exe = "chrome"
  }

  if(is_windows()){
    chrome_v_registry <- try(utils::readRegistry("Software\\Google\\Chrome\\BLBeacon", hive = "HCU"),
        silent = TRUE)
    if(!inherits(chrome_v_registry, "try-error"))
      version <- chrome_v_registry$version
    else return(numeric_version("0"))
  } else {
    info <- read_version(dir_exe = chrome_dir, file_exe = file_exe)
    if(any(is.na(info))) return(numeric_version("0"))
    version <- strsplit(info, split = " ")[[1]][3]
  }
  numeric_version(version)
}

#' @export
#' @title Path to "Google Chrome" executable
#' @description return the full path of "Google Chrome" executable
#' if found.
#' @return chrome executable full path in a character vector of length 1.
#' @family executable full path
#' @examples
#' if(is_available("chrome"))
#'   message(chrome_exec())
chrome_exec <- function() {
  locate_exec("chrome")
  is_available("chrome", error = TRUE)
  if(is_osx()){
    prg <- "Google Chrome"
  } else if (is_windows()) {
    prg <- "chrome.exe"
  } else {
    prg = "chrome"
  }

  file.path(.exec$chrome$dir, prg)
}

#' @export
#' @title Path to "LibreOffice" executable
#' @description return the full path of "LibreOffice" executable
#' if found.
#' @return executable full path in a character vector of length 1.
#' @family executable full path
#' @examples
#' if(is_available("libreoffice")) {
#'   message(libreoffice_exec())
#' }
libreoffice_exec <- function() {
  locate_exec("libreoffice")
  is_available("libreoffice", error = TRUE)
  prg <- "soffice"
  if (is_windows()) prg <- "soffice.com"
  file.path(.exec$libreoffice$dir, prg)
}

#' @export
#' @title Path to "node.js" executable
#' @description return the full path of "node.js" executable
#' if found.
#' @return executable full path in a character vector of length 1.
#' @family executable full path
#' @examples
#' if(is_available("node"))
#'   message(node_exec())
node_exec <- function() {
  locate_exec("node")
  prg <- "node"
  if(is_windows()) prg <- "node.exe"
  absolute_path(file.path(.exec$node$dir, prg))
}

#' @export
#' @title Path to "npm" executable
#' @description return the full path of "npm" executable
#' if found.
#' @return executable full path in a character vector of length 1.
#' @family executable full path
#' @examples
#' if(is_available("npm"))
#'   message(npm_exec())
npm_exec <- function() {
  locate_exec("npm")
  prg <- "npm"
  if(is_windows()) prg <- "npm.cmd"
  absolute_path(file.path(.exec$npm$dir, prg))
}


#' @export
#' @title Path to "python" executable
#' @description return the full path of "python" executable
#' if found.
#' @return executable full path in a character vector of length 1.
#' @family executable full path
#' @examples
#' if(is_available("python"))
#'   message(python_exec())
python_exec <- function() {
  locate_exec("python")
  is_available("python", error = TRUE)
  prg <- "python"
  if (is_windows()) prg <- "python.exe"
  file.path(.exec$python$dir, prg)
}

#' @export
#' @title Path to "pip" executable
#' @description return the full path of "pip" executable
#' if found.
#' @return executable full path in a character vector of length 1.
#' @family executable full path
#' @examples
#' if(is_available("pip"))
#'   message(pip_exec())
pip_exec <- function() {
  locate_exec("pip")
  is_available("pip", error = TRUE)
  prg <- "pip"
  if (is_windows()) prg <- "Scripts/pip.exe"
  file.path(.exec$pip$dir, prg)
}
davidgohel/locatexec documentation built on Feb. 17, 2021, 9:46 a.m.