确定所有程序包依赖项的最低R版本 [英] Determine minimum R version for all package dependencies

查看:147
本文介绍了确定所有程序包依赖项的最低R版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是软件包开发人员,并且想在DESCRIPTION文件中说明使用我的软件包所需的最低R版本.

I am a package developer and want to state the minimum R version required to use my package in the DESCRIPTION file.

available.packages解析软件包的描述,但结果(对于(机器)可读的)递归依赖项不是机器可读的,因为Imports和Depends字段是逗号分隔的文本,并且有时包含具有版本要求的软件包.

available.packages parses DESCRIPTIONS of packages, but the result is not (easily) machine readable to lookup recursive dependencies, since the Imports and Depends fields are comma separated text, and sometimes contain packages have version requirements.

解决方案描述于: 在不安装软件包的情况下列出R软件包依赖项不是递归解决方案.如果嵌套的依赖项需要R> 3.3,我想了解它.

The solution described in: Listing R Package Dependencies Without Installing Packages is not a recursive solution. If a nested dependency needed R > 3.3, I want to know about it.

我至少希望看到R的最低版本以及给定CRAN软件包的导入,链接和依赖软件包.最好列出列出最低R或软件包版本的软件包.

At a minimum, I would like to see the minimum version of R and imported, linked, and depends packages for a given CRAN package. Better still would be to list the package or packages which set the minimum R or package version.

通过消除对版本要求更高的依赖项,我可以为更多无法解决的具有系统旧版本的R用户提供服务:有些仍在R 2.x上.

By eliminating dependencies which have higher version requirements, I can serve more people with institutionally old R versions they can't fix: some are still on R 2.x.

推荐答案

min_r_version <- function(package="ggplot2", exclude_main_pkg=TRUE) {

  purrr::walk(c("tools", "purrr", "devtools", "stringi", "tidyr", "dplyr"), 
              require, character.only=TRUE)

  deps <- package_dependencies(package, recursive=TRUE)

  if (exclude_main_pkg) {
    pkgs <- deps[[1]]
  } else {
    pkgs <- c(package, deps[[1]])
  }

  available.packages() %>% 
    as_data_frame() %>% 
    filter(Package %in% pkgs) %>% 
    select(Depends)  %>% 
    unlist() -> pkg_list

  # if main pkg only relied on core R packages (i.e. pkgs that aren't in CRAN) and we 
  # excluded the pkg itself from the min version calculation, this is an edge case we need
  # to handle.

  if (length(pkg_list) == 0) return("Unspecified")

  stri_split_regex(pkg_list, "[,]") %>%
    unlist() %>%
    trimws() %>%
    stri_match_all_regex(c("^R$|^R \\(.*\\)$")) %>%
    unlist() %>%
    discard(is.na(.)) %>%
    unique() %>%
    stri_replace_all_regex("[R >=\\(\\)]", "") %>%
    data_frame(vs=.) %>%
    separate(vs, c("a", "b", "c"), fill="right") %>%
    mutate(c=ifelse(is.na(c), 0, c)) %>%
    arrange(a, b, c) %>%
    tail(1) %>%
    unite(min, a:c, sep=".") -> vs

  return(vs$min)

}

# did we handle the edge cases well enought?
base <- c("base", "compiler", "datasets", "grDevices", "graphics", "grid", "methods", "parallel", "profile", "splines", "stats", "stats4", "tcltk", "tools", "translations")
(base_reqs <- purrr::map_chr(base, min_r_version))
##  [1] "Unspecified" "Unspecified" "Unspecified" "Unspecified" "Unspecified"
##  [6] "Unspecified" "Unspecified" "Unspecified" "Unspecified" "Unspecified"
## [11] "Unspecified" "Unspecified" "Unspecified" "Unspecified" "Unspecified"

# a few of the "core" contributed pkgs rely on a pkg or two outside of base
# but many only rely on base packages, to this is another gd edge case to
# text for.
contrib <- c("KernSmooth", "MASS", "Matrix", "boot", "class", "cluster", "codetools", "foreign", "lattice", "mgcv", "nlme", "nnet", "rpart", "spatial", "survival")
contrib_reqs <- purrr::map_chr(contrib, min_r_version)
##  [1] "Unspecified" "Unspecified" "3.0.0"       "Unspecified" "3.1.0"      
##  [6] "Unspecified" "Unspecified" "Unspecified" "Unspecified" "3.0.2"      
## [11] "3.0.0"       "Unspecified" "Unspecified" "Unspecified" "3.0.1"      

# See what the min version of R shld be for some of my pkgs
min_r_version("ggalt") # I claim R (>= 3.0.0) in DESCRIPTION
## [1] "3.1.2"

min_r_version("curlconverter") # I claim R (>= 3.0.0) in DESCRIPTION
## [1] "3.1.2"

min_r_version("iptools") # I claim R (>= 3.0.0) in DESCRIPTION
## [1] "3.0.0"

这篇关于确定所有程序包依赖项的最低R版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆