att_amend_desc() drops version constraints when a package appears under two types in DESCRIPTION
Nobody has claimed this yet.
- #141 by @VincentGuyader — closed without merging
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 68/100
Research direction
Start in R/att_to_description.R at att_to_desc_from_is(), especially the duplicate-collapse pipeline around lines 367-374. Reproduce the issue with inst/dummypackage and att_amend_desc(), then inspect the resulting dependencies with desc::desc_get_deps(). Done means duplicate package rows resolve Imports over Suggests, preserve any written version constraint using the most restrictive constraint, and produce the same result regardless of row order.
Written by the indexing model from the issue text.
Description
The invariant
A version constraint written in DESCRIPTION must never disappear from an att_amend_desc() run. If a maintainer wrote pkg (>= 1.2.0), that constraint is load-bearing and attachment has no basis to silently reset it to *.
That invariant is violated today whenever a package appears under two types in DESCRIPTION (for example Imports: pkg (>= 1.2.0) and Suggests: pkg). The two rows are collapsed by row position rather than by a rule, so the constraint survives or is silently replaced by * depending on where the rows happen to sit in the frame.
The type conflict has a correct answer too: a package present in both Imports and Suggests should resolve to Imports, the stronger requirement. That is a semantic precedence, not an ordering question. But the version is the part that must not be lost.
Where
R/att_to_description.R, lines 367-374, in att_to_desc_from_is():
deps_new <- data.frame(
type = c(rep("Imports", length(imports)), rep("Suggests", length(suggests))),
package = all_packages, stringsAsFactors = FALSE) %>%
merge(deps_orig[,c("package", "version")],
by = "package", sort = TRUE, all.x = TRUE, all.y = FALSE) %>%
.[,c("type", "package", "version")] %>%
.[order(.$type, .$package), , drop = FALSE] %>%
.[!duplicated(.$package),]
deps_orig may hold several rows for the same package (one per type). The merge() is on package only, so it multiplies the row: one output row per original type, all carrying the type assigned by the scan but different version values. order(.$type, .$package) cannot separate them, since those duplicate rows share the same type and the same package. !duplicated() therefore keeps whichever row merge() happened to emit first.
Evidence: the outcome flips on row position alone
Traced on a copy of inst/dummypackage with glue pinned in Imports, glue also being listed in Suggests:
### deps_orig (glue rows) ###
type package version
2 Imports glue >= 1.2.0
5 Suggests glue *
### scan result ###
imports contains glue: FALSE
suggests contains glue: TRUE
### deps_new (glue rows) ###
type package version
11 Suggests glue *
Result: Imports: glue (>= 1.2.0) becomes Suggests: glue. The pin is gone and no message is emitted, because glue is still present in the output, so it never enters the removed set reported at lines 416-420.
Running the identical merge / order / !duplicated pipeline on a minimal two-row deps_orig keeps >= 1.2.0 instead. Same code, opposite result, decided purely by the position of the rows in the full frame.
Expected behaviour
When collapsing several DESCRIPTION rows for one package:
- Preserve the version constraint through the collapse. A constraint present on any of the collapsed rows must appear on the result. If several rows carry constraints, keep the most restrictive one rather than the first encountered. A constraint is only ever dropped when the maintainer removes it from
DESCRIPTION. - Resolve the type by precedence,
Importswinning overSuggests, rather than by position. - Never let the row order in
deps_origchange the result.
Point 1 is the invariant; points 2 and 3 are how it is achieved. Note that 1 is independent of the type: even if the package legitimately ends up in Suggests, a version written by hand in DESCRIPTION should still be carried over rather than reset to *.
Note on scope
Scan-level precedence already behaves correctly: a package detected in both R/ and tests/ lands in Imports, verified on dummypackage. That path works because order(.$type, ...) sorts "Imports" before "Suggests" alphabetically, so the dedup keeps the right row. It is worth making that precedence explicit rather than relying on the alphabetical accident, since it silently stops working if a type is ever renamed or a third type is introduced.
This is distinct from #139: there is no scan coverage problem here. The package is correctly detected. The defect is entirely in how duplicate DESCRIPTION rows are collapsed, and it reproduces without involving inst/ or any unscanned directory.
Repro
pkg <- <copy of inst/dummypackage>
d <- desc::desc(file = file.path(pkg, "DESCRIPTION"))
d$set_dep("glue", type = "Imports", version = ">= 1.2.0")
d$write()
attachment::att_amend_desc(path = pkg, document = FALSE, use.config = FALSE)
desc::desc_get_deps(file.path(pkg, "DESCRIPTION"))
#> glue is now "Suggests" with version "*"; the ">= 1.2.0" pin is lost, silently
- Dominant language
- R
- Stars
- 111
- Forks
- 14
- PR merge metrics
- No merged PRs in 30d
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from ThinkR-open/attachment
-
att_amend_desc() wipes nearly every dependency when a non-R Depends entry is no longer detectedPossibly taken @VincentGuyader claimed this 54 days ago. Open
Difficulty 3/5 1-2 days Newbie friendliness 35/100
ThinkR-open/attachment#146 ·
-
att_amend_desc() should not drop version constraints already set in DESCRIPTIONMay be free again A pull request for this issue was closed without being merged. Open
Difficulty 4/5 3-5 days Newbie friendliness 55/100
ThinkR-open/attachment#139 ·
All issues in ThinkR-open/attachment
Similar issues
-
Difficulty 1/5 Under an hour Newbie friendliness 88/100
leppott/BioMonTools#162 ·
-
publications
Difficulty 1/5 Under an hour Newbie friendliness 85/100
epiforecasts/epiforecasts.github.io#161 ·
Maintainers usually reply within 1 day
-
Label `{sas}` chunk source as `sas` instead of `txt`, so it gets syntax highlightingPossibly taken @michaelmayer2 claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
microbiome/OMA#1031 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
ThinkR-open/golem#1265 ·