desc
desc copied to clipboard
Treat `Config/Needs/website` like `Imports`?
I ran use_tidy_description() on a package with:
Config/Needs/website:
tidyverse/tidytemplate
and it converted it to:
Config/Needs/website:tidyverse/tidytemplate
Notice that it also removed the space, which seems wrong. At the very least I think it should keep that.
I managed to reproduce this with dev desc. The other weird thing is that if you run use_tidy_description() again on the "tidied" file, then it adds the space back.
tf <- tempfile()
# With Config/Needs/website
text <- "Config/Needs/website:\n\ttidyverse/tidytemplate"
desc <- desc::description$new(text = text)
desc$normalize()
desc$write(file = tf)
readLines(tf)
#> [1] "Config/Needs/website:tidyverse/tidytemplate"
# With Imports
text <- "Imports:\n\trlang"
desc <- desc::description$new(text = text)
desc$normalize()
desc$write(file = tf)
readLines(tf)
#> [1] "Imports:" " rlang"
# Notice how it actually adds the space back if you run it again?
text <- "Config/Needs/website:tidyverse/tidytemplate"
desc <- desc::description$new(text = text)
desc$normalize()
desc$write(file = tf)
readLines(tf)
#> [1] "Config/Needs/website: tidyverse/tidytemplate"
Created on 2022-01-25 by the reprex package (v2.0.1)
I think the removal of that white space happens right here? https://github.com/r-lib/desc/blob/daece0e5816e17a461969489bfdda2d50b4f5fe5/R/description.R#L809
Came here to say the same thing 😄
It would be great if it behaves just like Imports/Suggests, namely on package separator.
It doesn't require a lot of custom code to achieve part of it, but it would be great not to have it (or at least an option to enable this identical behavior).
tf <- tempfile()
text <- "Package: test\nImports: tdplyr, tibble\nConfig/Needs/website: tidyverse/tidytemplate, r-lib/desc"
# Single line for Needs
desc <- desc::description$new(text = text)
desc$normalize()
desc$write(file = tf)
readLines(tf) |> paste0(collapse = "\n") |> cat()
#> Package: test
#> Imports:
#> tdplyr,
#> tibble
#> Config/Needs/website: tidyverse/tidytemplate, r-lib/desc
#
desc <- desc::description$new(text = text)
desc$normalize()
desc_field_name <- "Config/Needs/website"
if (desc$has_fields(desc_field_name)) {
tmp_list <- desc$get_list(desc_field_name)
desc$set_list(desc_field_name, tmp_list, sep = ",\n ")
}
desc$write(file = tf)
readLines(tf) |> paste0(collapse = "\n") |> cat()
#> Package: test
#> Imports:
#> tdplyr,
#> tibble
#> Config/Needs/website: tidyverse/tidytemplate,
#> r-lib/desc
Created on 2023-10-25 with reprex v2.0.2