Offline Installation of R packages

2019-01-23 09:58发布

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 etc).

I am able to install packages if I use internet outside of my institute.

So, I am looking for an offline way to install packages. Please provide a detailed solution, I have just started using R.

Before writing this question I did look at this earlier asked question but did not quite understand the terms which have been used here (they are very direct). I am a newbie, please provide me a detailed solution. Offline install of R package and dependencies

Help will really be appreciated. I am really stuck here. I am not able to do anything.

Thank you.

1条回答
forever°为你锁心
2楼-- · 2019-01-23 10:32

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"
       )
查看更多
登录 后发表回答