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 버전의 날짜를 확인한 다음 나중에 패키지를 설치하지 마십시오. (R 스크립트가 아닐 것입니다.) 포괄적 인 바이너리 저장소가 없으므로 특정 버전의 R 및 특정 OS에 적합한 빌드 도구 세트를 사용할 수 있어야합니다. 다른 방법은 useRs가 뒤로 가고 그 문제를 해결할 이유를 결정하는 것입니다. –
그리고이 질문에 대한 두 번째 대답은 재귀적인 해결책을 제시했습니다. 어쩌면 이것이 중복 된 것일 수도 있습니다 (체크 표시가 된 해결책이 완전히 만족 스럽더라도)? 나는 마킹을 복제물로 잡을 것이지만 요구 사항에 대한보다 완전한 설명을 포함하도록 질문을 편집하지 않는 한 마킹 할 것입니다. –
불행히도 이것은 잠재적 인 위험에 처할 수 있습니다. 당신은 ['rodham'] (https://cran.rstudio.com/web/packages/rodham/)과 같은 패키지를 가지고 있는데 그것은 _claim_> = 2.1.0이지만 _actually_ need> = 3.2.0은 함수 ('trimws()')는 3.2.0에서 소개되었으며 2.1.0에서는 사용할 수 없습니다. 3.2.0이 종료되고 CRAN 테스트가 현재 버전과 devel 버전에만있는 경우 CRAN에 도입 되었기 때문에이 종속성 오류가 누락됩니다. 나는 각각의 R 버전으로 도커 이미지를 만들고, 판 버전을 결정하기 위해 pkg 테스트를 실행하는 것이 더 낫다고 생각합니다. 매우 자동화가 가능합니다. – hrbrmstr