R/install_modules.R

Defines functions install_modules

Documented in install_modules

#' Downloads and install modules for python
#'
#' Runs command line installation of python modules and can select whether to upgrade the python module manager 'pip'.
#'
#' @param modules Specify a character vector of all python modules to install
#' @param upgrade_pip Specify whether to upgrade the module manager before install i.e. to get the most updated versions for your python version
#' @return Installed python modules
#'
#'
#'
#' @examples
#' install_modules(modules = c("keras", "tensorflow", "scikit-learn==0.19.1"))
#' install_modules(modules = c("keras", "tensorflow", "scikit-learn==0.19.1"), upgrade_pip = F)
#' @export


install_modules = function(modules, upgrade_pip = T){
  if(grepl("Windows",Sys.getenv()['OS'])){
    if(upgrade_pip == T){
      shell("python -m pip install --upgrade pip")
    } else {
    }
    if(length(modules) == 0){
      warning("No python modules have been specified")
    } else {
      for(a in modules){
        shell(paste0("python -m pip install ",a))
      }
    }
  } else {
    if(upgrade_pip == T){
      system("python3 -m pip3 install --upgrade pip3")
    } else {
    }
    if(length(modules) == 0){
      warning("No python modules have been specified")
    } else {
      for(a in modules){
        system(paste0("python3 -m pip3 install ",a))
      }
    }
  }
}
GitTFJ/addeR documentation built on Sept. 6, 2022, 8:55 p.m.