How to download the entire CRAN repository?

前端 未结 1 1756

For offline linux machines without Internet, installing R packages with lots of dependencies is a nightmare. I found couple of posts in SE discussing on how to create a loca

1条回答
  •  不思量自难忘°
    2020-12-20 01:57

    You can use the function available.packages to find the available packages.

    pkgnames <- available.packages()[,1]
    

    If you like web scraping you can practice as follows.

    library(rvest)
    pkgs <- read_html("https://cran.r-project.org/web/packages/available_packages_by_name.html")
    tab <- html_nodes(pkgs, "table") %>% html_table(fill = TRUE)
    
    pkgnames <- tab[[1]][1]$X1
    pkgnames <- pkgnames[nchar(pkgnames)>0]
    

    DON'T RUN THESE UNLESS YOU WANT TO INSTALL (OR DOWNLOAD) A LOT OF PACKAGES!!

    #sapply(pkgnames, install.packages)
    #sapply(pkgnames, install.packages)
    

    You can run this line to show that it works.

    sapply(pkgnames[1:2], install.packages)
    

    You can replace the install.packages with download.packages along with the destdir argument to save it to your corporate directory.

    0 讨论(0)
提交回复
热议问题