1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
|
proj_desc <- function(path = proj_get()) {
desc::desc(file = path)
}
proj_version <- function() {
proj_desc()$get_field("Version")
}
proj_deps <- function() {
proj_desc()$get_deps()
}
proj_desc_create <- function(name, fields = list(), roxygen = TRUE) {
fields <- use_description_defaults(name, roxygen = roxygen, fields = fields)
# https://github.com/r-lib/desc/issues/132
desc <- desc::desc(text = glue("{names(fields)}: {fields}"))
tidy_desc(desc)
tf <- withr::local_tempfile()
desc$write(file = tf)
write_over(proj_path("DESCRIPTION"), read_utf8(tf))
# explicit check of "usethis.quiet" since I'm not doing the printing
if (!is_quiet()) {
desc$print()
}
}
# Here overwrite means "update the field if there is already a value in it,
# including appending".
proj_desc_field_update <- function(key, value, overwrite = TRUE, append = FALSE) {
check_string(key)
check_character(value)
check_bool(overwrite)
desc <- proj_desc()
old <- desc$get_list(key, default = "")
if (all(value %in% old)) {
return(invisible())
}
if (!overwrite && length(old) > 0 && any(old != "")) {
ui_abort("
{.field {key}} has a different value in DESCRIPTION.
Use {.code overwrite = TRUE} to overwrite.")
}
ui_bullets(c("v" = "Adding {.val {value}} to {.field {key}}."))
if (append) {
value <- union(old, value)
}
# https://github.com/r-lib/desc/issues/117
desc$set_list(key, value)
desc$write()
invisible()
}
|