Offline Installation of R packages

前端 未结 1 860
不思量自难忘°
不思量自难忘° 2020-12-15 02:12

My institute uses proxy server, and no one is able to install packages in a usual way. (i.e downloading binary file from CRAN and then choosing Mirro and the installing etc

相关标签:
1条回答
  • 2020-12-15 02:38

    This is my work around. Might be helpful for you too.

    Idea: Download packages with their dependencies through internet and install packages offline.

    # Set Mirror to download packages    
    options(repos=structure(c(CRAN="http://cran.ma.imperial.ac.uk/")))
    
     # Set Working Directory   
        setwd(file.path(
            "D:"
          , "User"
          , "DownloadingPackagesWithDependencies"
          )
          )
    
    
    getPackages <- function(packs){
      packages <- unlist(
          tools::package_dependencies(
              packs
            , available.packages()
            , which=c("Depends", "Imports")
            , recursive=TRUE
            )
          )
        packages <- union(packs, packages)
        packages
      }
    
    # Specify Packages to Download with their dependencies also   
    Packages <- getPackages(
                    c(
                      "ggplot2"
                      )
                    )
    
    
    download.packages(
        pkgs=Packages
      , destdir=getwd()
      , type="source")
    
    # Install packages from local drive
        install.packages(
            pkgs="ggplot2_0.9.3.1.tar.gz"
          , repos = NULL
          , type="source"
           )
    
    0 讨论(0)
提交回复
热议问题