从文件夹安装多个包

问题描述 投票:1回答:3

我有一个文件夹,其中包含我在之前的计算机中使用的所有库(> 100个压缩的二进制文件)。现在我换了一台新电脑。我希望在新机器中安装所有这些软件包。由于托管的数据,新机器没有直接的互联网连接。所以我无法直接安装它们。我也不想手动安装它们。有没有办法我可以自动化这个过程并让R读取文件夹,并将软件包安装在该文件夹中?先感谢您。

我想像list.filesgrep这样的函数可能会有帮助吗?

我使用Windows 7和R 3.1.0。

r install.packages
3个回答
3
投票

试试这个

setwd("path/packages/") #set the working directory to the path of the packages
pkgs <- list.files()

install.packages(c(print(as.character(pkgs), collapse="\",\"")), repos = NULL)

1
投票

我们在非互联网服务器上有300多个包。所以我们将所有包复制到指定目录。

setwd("location/to/a/specified/directory") #set the working directory to the path of the packages
pkgs1 <- list.files()

install.packages(pkgs1 , repos = NULL, type = source )

0
投票

我不得不添加type =“binary”以使其适用于我。

setwd("path/packages/") #set the working directory to the path of the packages
pkgs <- list.files()

install.packages(c(print(as.character(pkgs), collapse="\",\"")), repos = NULL, type= "binary")
© www.soinside.com 2019 - 2024. All rights reserved.