Skip to content
Snippets Groups Projects
Select Git revision
  • c643c339dccd83f3c84193d94c5e33dbcab692c9
  • main default protected
  • docker-images protected
  • docs protected
  • helm protected
5 results

install_r_packages.R

Blame
  • install_r_packages.R 1.52 KiB
    #!/usr/bin/env Rscript
    ### Name : install_r_packages.R
    ### Folder : ~/scripts
    ### Date : 17/04/2023
    ### Aim : Install all packages from CRAN, BioConductor or github, requiered in the Shiny app.
    
    ### Install pak packages first
    # Specify your packages
    my_packages <- c("pak","pkgcache","pkgdepends","pillar", "shinipsum")
    # Extract not installed packages                                       
    not_installed <- my_packages[!(my_packages %in% installed.packages()[ , "Package"])]
    # Check if packages are yet installed
    if(length(not_installed)){
        print("packages needed to install in the basic image ...")
        install.packages(not_installed, dependencies= NA)
        print("...done")
    }else{
        print("packages previously installed in the basic image")
    }
    
    #### Load file with the list of packages
    packages_list <- read.csv(file = "/opt/scripts/packages_to_install.csv", header = TRUE, sep = ";", stringsAsFactors = FALSE)
    print("Installation for other packages needed : ")
    print(paste(packages_list$Package_name, sep = "",collapse = ","))
    
    ### Install packages with dependencies with pak packages
    if (length(packages_list$Package_name)>=5){
      print ("at least 5 packages to install")
        for(i in 1:length(packages_list$Package_name) ) {
            print(packages_list$Package_name[i])
    	    pak::pkg_install(pkg=packages_list$Package_name[i])
        }
    }else {
        print("packages to install : ")
        print(paste(packages_list$Package_name, sep = "",collapse = ","))
        pak::pkg_install(pkg=packages_list$Package_name)
    }
    # clean the cache of pak
    pak::cache_clean()