我有一个文件夹,其中包含我在以前的计算机中使用的所有库(>100 个压缩二进制文件)。现在我换了一台新电脑。我希望所有这些软件包都安装在新机器的 R 中。由于托管的数据,新机器没有直接的互联网连接。所以我不能直接安装它们。我也不想手动安装它们。有没有一种方法可以使这个过程自动化并使 R 读取文件夹,并将包安装在该文件夹中?先感谢您。
我猜像这样的功能list.files
并且grep
可能在这里有所帮助?
我使用 Windows 7 和 R 3.1.0。
我有一个文件夹,其中包含我在以前的计算机中使用的所有库(>100 个压缩二进制文件)。现在我换了一台新电脑。我希望所有这些软件包都安装在新机器的 R 中。由于托管的数据,新机器没有直接的互联网连接。所以我不能直接安装它们。我也不想手动安装它们。有没有一种方法可以使这个过程自动化并使 R 读取文件夹,并将包安装在该文件夹中?先感谢您。
我猜像这样的功能list.files
并且grep
可能在这里有所帮助?
我使用 Windows 7 和 R 3.1.0。
尝试这个
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)
我们在非 Internet 服务器上有 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 )
我必须添加 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")
如果您使用的是 ubuntu 或任何其他 linux 发行版。确定存储下载包的 tmp 文件夹。通常它是“/tmp/Rtmp”文件夹。您需要将工作目录设置为此文件夹。
setwd("location of the directory")
pkg <- list.files()
install.packages(pkg, repos = NULL, type = "source")
这对我有用。