为何Windows下R的install.packages会出现包版本不兼容问题?
Windows下R包安装的依赖版本不匹配问题
在Windows系统测试R包安装时,发现原本正常的包依赖解析出现版本不匹配错误。该问题出现在以下场景:某个包提供无需编译的源码包,但其依赖包的源码包需要编译,因此会回退使用依赖包的旧版二进制包,但同时仍安装该包的新版,导致依赖不满足,安装失败。
示例:tinytex与xfun的安装冲突
> utils::install.packages("tinytex", repos = "https://cloud.r-project.org") Installing package into ‘C:/Users/User/Documents/R/win-library/3.6’ (as ‘lib’ is unspecified) also installing the dependency ‘xfun’ There are binary versions available but the source versions are later: binary source needs_compilation xfun 0.22 0.32 TRUE tinytex 0.31 0.41 FALSE Binaries will be installed trying URL 'https://cloud.r-project.org/bin/windows/contrib/3.6/xfun_0.22.zip' Content type 'application/zip' length 323923 bytes (316 KB) downloaded 316 KB package ‘xfun’ successfully unpacked and MD5 sums checked The downloaded binary packages are in C:\Users\User\AppData\Local\Temp\Rtmp6xfEaC\downloaded_packages installing the source package ‘tinytex’ trying URL 'https://cloud.r-project.org/src/contrib/tinytex_0.41.tar.gz' Content type 'application/x-gzip' length 32910 bytes (32 KB) downloaded 32 KB * installing *source* package 'tinytex' ... ** package 'tinytex' successfully unpacked and MD5 sums checked ** using staged installation ** R ** inst ** byte-compile and prepare package for lazy loading Error in loadNamespace(j <- i[[1L]], c(lib.loc, .libPaths()), versionCheck = vI[[j]]) : namespace 'xfun' 0.22 is being loaded, but >= 0.29 is required Calls: <Anonymous> ... namespaceImportFrom -> asNamespace -> loadNamespace Execution halted ERROR: lazy loading failed for package 'tinytex' * removing 'C:/Users/User/Documents/R/win-library/3.6/tinytex' The downloaded source packages are in ‘C:\Users\User\AppData\Local\Temp\Rtmp6xfEaC\downloaded_packages’ Warning message: In utils::install.packages("tinytex", repos = "https://cloud.r-project.org") : installation of package ‘tinytex’ had non-zero exit status
疑问与困惑
无法理解为何install.packages会安装不兼容的包组合,而非选择最新的可用兼容组合。在这个例子中,tinytex 0.31仅要求xfun版本≥0.19,两个旧版二进制包可以正常工作,也可以通过安装时指定type = "binary"强制该行为。但install.packages难道不应该识别到最新版tinytex的依赖不可用,从而避免安装失败吗?这是Windows下的预期行为,还是一个bug?
测试环境:Windows 11系统下的R 3.6.3版本。
关于旧版R的补充说明
我知道R 3.6.3不是最新的主版本,但我关注的是依赖处理行为——无论使用哪个R版本,只要存在二进制包和源码包的特定组合,都可能出现这个问题。如何避免这种情况?而且就我看来,所选的包组合不符合逻辑,这是否应该作为依赖处理逻辑的bug上报?
问题上报情况
我已于2022年8月30日将此问题上报为bug #18396,等待结果。
内容的提问来源于stack exchange,提问作者Jesse
相关产品推荐
相关产品推荐

