简体   繁体   English

r update.packages()不更新由其他包导入的包

[英]r update.packages() not updating packages that are imported by other packages

I recently updated to R 3.5.1 from 3.4.3. 我最近从3.4.3更新到R 3.5.1。 I updated my packages as follows: 我更新了我的包,如下所示:

(a) copied packages from my old library into my new library (taking care not to overwrite the base packages) (a)将旧库中的包复制到我的新库中(注意不要覆盖基础包)

(b) ran update.packages(ask = FALSE, dependencies = TRUE) (b)运行update.packages(ask = FALSE, dependencies = TRUE)

I found that a number of packages didn't install where they were listed as imports of other packages as they had 'been created with an r version with different internals, and needs to be reinstalled'. 我发现许多软件包没有安装在它们作为其他软件包的导入列出的地方,因为它们是“使用不同内部的r版本创建的,需要重新安装”。

Somewhat frustratingly, this message seemed to be iterating through some hidden list of associated or linked packages but only telling me there was a problem for one package at a time; 有点令人沮丧的是,这条消息似乎正在迭代一些隐藏的相关或链接包列表,但只告诉我一次一个包有问题; ie I would install the package that had the wrong version, then try reinstalling the package it had blocked from installing, only to get the error repeated for a different package. 即我会安装具有错误版本的软件包,然后尝试重新安装它已阻止安装的软件包,只是为了不同的软件包重复出错。 I had to go through this multiple times until there were no more incorrect-version associated packages and finally the package I needed to use could be installed / updated. 我不得不经历多次,直到没有更多不正确版本的相关软件包,最后我需要使用的软件包可以安装/更新。

Also - I note that some packages were installed from source (these were frequently but not exclusively the ones that caused the 'different internals' error for associated packages above). 另外 - 我注意到一些软件包是从源代码安装的(这些软件包经常但不完全是导致上述相关软件包出现'不同内部'错误的软件包)。 I do have Rtools installed so not a problem for me but just an observation as update.packages was doing this every time it encountered a source version that was more up to date than a windows binary (I have a windows 10 PC). 我确实安装了Rtool,所以对我来说不是问题,但只是观察,因为update.packages每次遇到比Windows二进制文件更新的源版本时都会这样做(我有一台Windows 10 PC)。

I conclude from all this that update.packages skipped a lot of packages and did not in fact update them for some reason? 我从这一切得出结论, update.packages跳过了很多软件包,实际上并没有因为某种原因更新它们? I'm still finding packages that did not update. 我仍然在寻找没有更新的软件包。

For example: 例如:

> DescTools::Gmean(x)
Error: package ‘expm’ was installed by an R version with different internals; it needs to be reinstalled for use with this R version

Looking at the CRAN entry for DescTools here indicates that the package expm is not a dependency but is imported. 这里查看DescTools的CRAN条目表明包expm不是依赖项,而是导入的。

However ?import.packages says of the dependencies argument: 但是?import.packages说的dependencies参数:

dependencies: 依赖关系:

logical indicating whether to also install uninstalled packages which these packages depend on/link to/import/suggest (and so on recursively). 逻辑指示是否还安装这些软件包依赖/链接到/ import / suggest的已卸载软件包(等等递归)。 Not used if repos = NULL. 如果repos = NULL,则不使用。 Can also be a character vector, a subset of c("Depends", "Imports", "LinkingTo", "Suggests", "Enhances"). 也可以是字符向量,c的子集(“Depends”,“Imports”,“LinkingTo”,“Suggests”,“Enhances”)。

Only supported if lib is of length one (or missing), so it is unambiguous where to install the dependent packages. 仅当lib的长度为1(或缺失)时才受支持,因此在哪里安装依赖包是明确的。 If this is not the case it is ignored, with a warning. 如果不是这种情况,则会被忽略,并发出警告。

The default, NA, means c("Depends", "Imports", "LinkingTo"). 默认值NA表示c(“取决于”,“导入”,“链接到”)。 TRUE means to use c("Depends", "Imports", "LinkingTo", "Suggests") for pkgs and c("Depends", "Imports", "LinkingTo") for added dependencies: this installs all the packages needed to run pkgs, their examples, tests and vignettes (if the package author specified them correctly). TRUE表示为pkgs和c(“取决于”,“Imports”,“LinkingTo”)使用c(“Depends”,“Imports”,“LinkingTo”,“Suggests”)来添加依赖项:这将安装所需的所有包运行pkgs,他们的例子,测试和小插曲(如果包作者正确指定了它们)。

In all of these, "LinkingTo" is omitted for binary packages. 在所有这些中,对于二进制包,省略了“LinkingTo”。

This implies that update.packages(...dependencies = TRUE) should have also updated and / or installed all packages imported by other packages as well. 这意味着update.packages(...dependencies = TRUE)应该更新和/或安装其他包导入的所有包。

What am I missing? 我错过了什么?

I had the same issue after update to R 3.6.0. 更新到R 3.6.0后,我遇到了同样的问题。 In my case a slight modification of Carlos Santillan's solution solved the problem: 在我的例子中,Carlos Santillan的解决方案略有改动解决了这个问题:

for (i in 2:length(.libPaths())) {
  lib <- .libPaths()[i]
  install.packages( 
    lib  = .libPaths()[1] ,
    pkgs = as.data.frame(installed.packages(lib), stringsAsFactors=FALSE)$Package,
    type = 'source'
  )
}

In my setup .libPaths() retuns the following: 在我的设置中.libPaths()返回以下内容:

> .libPaths()
[1] "/home/wassermann/R/x86_64-pc-linux-gnu-library/3.6" "/usr/local/lib/R/site-library"                
[3] "/usr/lib/R/site-library"                            "/usr/lib/R/library"    

The first directory in .libPaths() is writeable at the user level, the other three are read-only. .libPaths()中的第一个目录在用户级别是可写的,其他三个目录是只读的。 The code iterates over all packages in read-only folders and installs their newer versions in the user writeable directory. 代码遍历只读文件夹中的所有包,并将其较新版本安装在用户可写目录中。 It's not optimal in the sense that it may iterate over some packages more than once, but you need to run it only once and after that all packages install without the iritating "different internals" error. 它不是最优的,因为它可能会多次迭代某些包,但是你需要只运行一次,之后所有的包都会安装而不会出现“不同的内部”错误。

It looks like dependencies = TRUE is not a parameter for update.packages instead it passes it parameter to the install.packages 看起来依赖= TRUE不是update.packages的参数,而是将它传递给install.packages

The documentation 文档

https://www.rdocumentation.org/packages/utils/versions/3.5.1/topics/update.packages https://www.rdocumentation.org/packages/utils/versions/3.5.1/topics/update.packages

says

Take care when using dependencies (passed to install.packages) with update.packages, for it is unclear where new dependencies should be installed. 使用update.packages使用依赖项(传递给install.packages)时要小心,因为不清楚应该在哪里安装新的依赖项。 The current implementation will only allow it if all the packages to be updated are in a single library, when that library will be used. 当使用该库时,如果要更新的所有包都在单个库中,则当前实现将仅允许它。

The following script will reinstall all packages 以下脚本将重新安装所有包

lib <- .libPaths()[1]
install.packages( 
    lib  = lib ,
    pkgs = as.data.frame(installed.packages(lib), stringsAsFactors=FALSE)$Package,
    type = 'source'
)

The following will update check if all packages need updating 以下将更新检查是否所有包都需要更新

lib <- .libPaths()[1]
update.packages( 
 oldPkgs = as.data.frame(installed.packages(lib), stringsAsFactors=FALSE)$Package,
  type = 'source',
  ask = FALSE
)

(above was modified from https://www.r-bloggers.com/update-all-user-installed-r-packages-again/ ) (上面是从https://www.r-bloggers.com/update-all-user-installed-r-packages-again/修改的)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM