att_amend_desc() wipes nearly every dependency when a non-R Depends entry is no longer detected
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 35/100
Hướng nghiên cứu
Start in R/att_to_description.R, especially att_to_desc_from_is(), and review the regression tests mentioned in issue #145. Reproduce the DESCRIPTION dependency loss with the supplied example, then verify the empty Depends case preserves dependencies and no longer emits an empty package message.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
att_amend_desc() can wipe almost every dependency from DESCRIPTION, silently, when the package carries a Depends: entry other than R that the code scan no longer detects.
Measured on attachment 1.1.0 from CRAN, so this is released behaviour and not a development regression.
Reprex
racine <- tempfile("depcran")
dir.create(racine)
file.copy(system.file("dummypackage", package = "attachment"), racine, recursive = TRUE)
pkg <- file.path(racine, "dummypackage")
# A Depends: entry that no scanned source mentions.
d <- desc::desc(file = file.path(pkg, "DESCRIPTION"))
d$set_dep("somedep", type = "Depends")
d$write()
nrow(desc::desc_get_deps(file.path(pkg, "DESCRIPTION")))
#> [1] 11
attachment::att_amend_desc(path = pkg, document = FALSE, must.exist = FALSE,
check_if_suggests_is_installed = FALSE, use.config = FALSE)
desc::desc_get_deps(file.path(pkg, "DESCRIPTION"))$package
#> [1] "R" "Rcpp"
Nine dependencies gone, magrittr, stats, glue, knitr, rmarkdown, testthat, utils, stringr and the somedep that triggered it. R and Rcpp survive only because the Depends and LinkingTo blocks further down re-append them.
The one visible hint is a message whose package list is empty:
Package(s) is(are) in category 'Depends'. Check your Description file to be sure it is really what you want.
Mechanism
R/att_to_description.R, in att_to_desc_from_is():
Other_depends_keep <- Other_depends[Other_depends$package %in% deps_new$package, ]
if (length(Other_depends_keep) != 0) {
message("Package(s) ", paste(Other_depends_keep$package, collapse = ", "), " is(are) in category 'Depends'. ...")
deps_new <- rbind(Other_depends_keep,
deps_new[-which(deps_new$package %in% Other_depends_keep$package), ])
}
Three steps, each harmless alone:
length()on a data frame is its column count, not its row count.Other_depends_keepkeeps its three columns even with zero rows, so the guard is true whenever the frame exists:
tab <- data.frame(type = "Depends", package = "somedep", version = "*")
vide <- tab[tab$package %in% character(0), ]
nrow(vide)
#> [1] 0
length(vide)
#> [1] 3
-
The branch therefore runs on an empty frame, and
Other_depends_keep$packageischaracter(0), sowhich(...)isinteger(0). -
x[-integer(0), ]keeps nothing. Negative indexing by an empty index vector is the classic R trap: the complement of "no rows" is not "all rows", it is the empty selection.
deps <- data.frame(type = "Imports", package = c("glue", "jsonlite"), version = "*")
nrow(deps[-which(deps$package %in% character(0)), ])
#> [1] 0
rbind() of two empty frames is empty, and desc$set_deps() then writes that.
Trigger
Narrow but ordinary: a Depends: entry other than R whose package the scan does not find in R/, tests/ or vignettes/. A package moved out of Depends and no longer used, a Depends on a data package referenced only by string, or the same inst/ situation as #139.
Fix
Two changes, either of which alone closes the data loss, and both are worth making:
- the guard becomes
nrow(Other_depends_keep) != 0, so the branch does not run on an empty frame and the message stops printing an empty list; - the subset becomes a logical negation,
deps_new[!deps_new$package %in% Other_depends_keep$package, ], which is correct for the empty case instead of being correct only by accident of a non-emptywhich().
I have a fix with regression tests coming in #145, which is already in that file.
- Ngôn ngữ chính
- R
- Star
- 111
- Fork
- 14
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của ThinkR-open/attachment
-
att_amend_desc() drops version constraints when a package appears under two types in DESCRIPTIONCó thể làm lại được Pull request cho issue này đã bị đóng mà không được merge. Đang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 68/100
ThinkR-open/attachment#140 ·
-
att_amend_desc() should not drop version constraints already set in DESCRIPTIONCó thể làm lại được Pull request cho issue này đã bị đóng mà không được merge. Đang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 55/100
ThinkR-open/attachment#139 ·
Tất cả issue của ThinkR-open/attachment
Issue tương tự
-
data_bio2rarify - doc - dimensions wrongCó thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 88/100
leppott/BioMonTools#162 ·
-
publications
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 85/100
epiforecasts/epiforecasts.github.io#161 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Label `{sas}` chunk source as `sas` instead of `txt`, so it gets syntax highlightingCó thể đã có người làm @michaelmayer2 đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
microbiome/OMA#1031 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
ThinkR-open/golem#1265 ·