【问题标题】:Offline installation of packages in RStudio在 RStudio 中离线安装包
【发布时间】:2014-03-09 06:34:53
【问题描述】:

由于安全协议,我正在使用没有 http||https 连接的工作终端。我在另一台计算机上手动下载了一些软件包,并尝试使用 RStudio 安装它们。当我在 RStudio 中运行时

install.packages(//filedir/package_file.zip,repos=NULL,type="source")

无论如何它都在尝试连接到在线存储库:

>>warning in istall.packages:
>>unable to resolve 'www.stats.ox.ac.uk'

但是当我通过 RGui 并使用 utils:::menuInstallLocal() 并使用弹出窗口时,它不会尝试通过服务器连接并安装我的本地文件。

我在 RStudio 中做错了什么?

我还希望能够在安装父包时自动安装依赖项和导入。

【问题讨论】:

标签: r rstudio


【解决方案1】:

假设您的计算机本地有 zip 存档格式的包。

RStudio 有一个简单的菜单选项

Tools>Install Packages > 在 Install from 选项中选择“Package Archive File”

浏览您需要安装的软件包文件。

安装后你可能想加载库,例如如果你已经安装了“tm”包,那么你可以运行命令

library(tm) # 加载库“tm”

希望它有效:)

【讨论】:

    【解决方案2】:

    不要使用参数type="source",因为您提供了一个 zip 文件的链接:

    这应该可以工作

    install.packages("yourlink.zip", repos=NULL)
    

    【讨论】:

    • 来自 rstudio:您好,看起来我们一直在强制检查 CRAN 的软件包更新,而不管其他设置如何。 This 应该在最新的预览版中得到修复 - 你可以尝试安装并运行它,如果它解决了你的问题,请告诉我们?
    【解决方案3】:

    步骤 1:- 在 PC 上安装 R base(64 位)和 R Studio。 步骤 2:- 插入 Pendrive 或 PC 上保存离线包文件夹的位置。 第三步:-。以编辑模式打开 R studio(R 脚本)。

    getDependencies <- function(packs){
      dependencyNames <- unlist(
        tools::package_dependencies(packages = packs, db = available.packages(),
                                    which = c("Depends", "Imports"),
                                    recursive = TRUE))
      packageNames <- union(packs, dependencyNames)
      # Remove base dependencies, these are installed with R and not published on CRAN
      basePackages <- c("base","compiler","datasets","graphics","grDevices","grid",
                        "methods","parallel","splines","stats","stats4","tcltk","tools","utils")
      packageNames <- setdiff(packageNames, basePackages)
    
      packageNames
    }
    
    
     packages <- getDependencies(c("tidyverse", "pacman"))
    setwd("E:/offline package R installation")
    pkgInfo <- download.packages(pkgs = packages, destdir = getwd(), type = "win.binary")
    # Save just the package file names (basename() strips off the full paths leaving just the filename)
    write.csv(file = "pkgFilenames.csv", basename(pkgInfo[, 2]), row.names = FALSE)
    

    Step5:在excel表格中获取所需包以及文件夹中的包后,将其存储在您想要的任何地方。之后在任何其他计算机上打开 R 编辑器。并执行以下代码

    # Set working directory to the location of the package files
    setwd("E:/offline package R installation")
    
    # Read the package filenames and install
    pkgFilenames <- read.csv("pkgFilenames.csv", stringsAsFactors = FALSE)[, 1]
    install.packages(pkgFilenames, repos = NULL, type = "win.binary")
    

    现在,您终于可以在任何计算机上轻松使用离线包及其 deoendancies 而无需任何互联网连接

    【讨论】:

      猜你喜欢
      • 2015-03-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-01-06
      • 2013-06-15
      • 2012-06-20
      相关资源
      最近更新 更多