如何下载整个 CRAN 存储库? [英] How to download the entire CRAN repository?

查看:70
本文介绍了如何下载整个 CRAN 存储库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于没有 Internet 的离线 linux 机器,安装具有大量依赖项的 R 包是一场噩梦.我在 SE 中发现了几篇讨论如何创建本地文件夹、复制所需的包 zip 文件并使用install.packages"进行安装的帖子.

但是,查找、下载大量软件包并将其上传到离线服务器是一项耗时的工作.所以,我想知道如何下载所有 CRAN 包的整个 zip 文件,以便我可以将它们放在本地离线机器的 http web 服务器目录中,并像一个真正的存储库一样工作.大小可能会很大,大约 200 GB,但对于企业环境,我认为应该是有意义的.

我在这里找到了一个指南,讨论如何成为官方 CRAN 镜像,但我不会成为官方的公共镜像.

请指教.提前致谢

解决方案

您可以使用 available.packages 函数来查找可用的包.

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

如果你喜欢网页抓取,你可以按照以下方法练习.

库(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]$X1pkgnames <- pkgnames[nchar(pkgnames)>0]

除非您想安装(或下载)大量软件包,否则不要运行这些软件!!

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

您可以运行此行以表明它有效.

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

您可以将 install.packages 替换为 download.packages 以及 destdir 参数,以将其保存到您的公司目录中.>

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 local folder, copy desired package zip files and install using 'install.packages'.

However, finding, downloading, and uploading lots of packages to an offline server is a time-consuming effort. So, I am wondering how can I download the entire zip file of all CRAN packages so I can put them in a http web server directory in my local offline machine and act like a real repository. The size probably will be very big around 200 GB, but for corporate environment, I think it should make sense.

I found a guide here discussing how to become an official CRAN mirror, but I am not going to be an official public mirror.

Please advise. Thanks in advance

解决方案

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.

这篇关于如何下载整个 CRAN 存储库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆