gpt4 book ai didi

r - 如何获得给定包所需的最低 R 版本?

转载 作者:行者123 更新时间:2023-12-01 00:52:02 24 4
gpt4 key购买 nike

如何检查软件包列表需要哪个版本的 R?理想情况下是这样的

minimumRVersion <- function(packageList = c(), return=c("list", "min", "mine")) {
# code to collate a list of minimum versions of R
# required for the listed packages.
# Optionally return min(list) or "is my R high enough?
return(result)
}

minVersion("RcppEigen")
# 2.15.1

minVersion(c("RcppEigen","OpenMx"), "min")
# 3.0

最佳答案

您可以使用 packageDescription功能,它允许您获取包要求。

我写了一个快速而肮脏的解决方案,请随时改进!

minimumRVersion <- function(packageList)
{
requirements <- NULL

for (p in packageList)
{
# Get dependencies for the package
dep <- packageDescription(p, fields = "Depends")

if (!is.na(dep))
{
# dep will be something like:
# "R (>= 3.1.0), grDevices, graphics, stats, utils"
# split by comma
dep <- unlist(strsplit(dep, ","))
# Find requirement for R (may not exist)
r.dep <- dep[grep("R \\(", dep)]
if (!length(r.dep))
r.dep <- NA
}
else
r.dep <- NA

requirements <- c(requirements, r.dep)
}

requirements
}

调用:
minimumRVersion(c("nlme", "MASS", "bootstrap", "knitr", "Hmisc"))

返回:
[1] " R (>= 3.0.0)" "R (>= 3.1.0)" " R (>= 2.10.0)" "R (>= 3.0.2)"  NA              

关于r - 如何获得给定包所需的最低 R 版本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30599951/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com