dependency_installer.R 1018 Bytes
Newer Older
pxp9's avatar
pxp9 committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34

# This function receives a list of packages to be installed before the execution of a script.
# For each package provided, it verifies that it is not installed already. If so, it proceeds to
# install it.
# ToDo: exception control for unexistent/misspelled packages.

install_dependencies <- function(dep_list) {
  
  # Deprecated since executing server is Ubuntu.
  #if(Sys.info()["sysname"] == "Windows"){
  #  dep_list[length(dep_list)+1] = "Rtools"
  #}
  for(p in dep_list){

    if(require(p, character.only = T) == FALSE){
      if(p == "dsBaseClient"){
        library(remotes)
        install_github("datashield/dsBaseClient", dependencies = TRUE)
      }else{
        if(p == "DSI"){
           library(remotes)
           install_github('datashield/DSI', ref = '1.3.3', dependencies = TRUE)
        }else{
           install.packages(p, dependencies = TRUE, repos = "https://cran.us.r-project.org")
        }
      }  
    }
    if(p != "Rtools"){
      library(p, character.only = T)
    }   
  }  
  
}