【问题标题】:Install multiple packages from a folder从一个文件夹安装多个包
【发布时间】:2014-11-19 20:50:32
【问题描述】:

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

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

我使用的是 Windows 7 和 R 3.1.0。

【问题讨论】:

    标签: r install.packages


    【解决方案1】:

    试试这个

    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)
    

    【讨论】:

      【解决方案2】:

      我们在非互联网服务器上有 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",正如答案stackoverflow.com/a/55922753/311618中所建议的那样
      【解决方案3】:

      我必须添加 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")
      

      【讨论】:

        【解决方案4】:

        如果您使用的是 ubuntu 或任何其他 linux 发行版。确定存储下载包的 tmp 文件夹。通常它是“/tmp/Rtmp”文件夹。您需要将工作目录设置为该文件夹。

                       setwd("location of the directory")
                       pkg <- list.files()
                       install.packages(pkg, repos = NULL, type = "source")
        

        这对我有用。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2015-05-31
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2016-04-30
          • 2011-03-29
          • 1970-01-01
          相关资源
          最近更新 更多