desc_get_field_safe: Get value from 'DESCRIPTION' file field (safe)

desc_get_field_safeR Documentation

Get value from DESCRIPTION file field (safe)

Description

Returns the value from a DESCRIPTION file field (aka key). Thin wrapper around desc::desc_get_field() that returns an informative string referring to the given key as default if the field is unset.

Usage

desc_get_field_safe(
  key,
  default = glue::glue("<No `{key}` field set in DESCRIPTION!>"),
  trim_ws = TRUE,
  squish_ws = trim_ws,
  file = "."
)

Arguments

key

The field to query.

default

Default value to return if key is not found.

trim_ws

Whether to trim leading and trailing whitespace from the value. Defaults to TRUE.

squish_ws

Whether to reduce repeated whitespace in the value. Defaults to trim_ws.

file

DESCRIPTION file to use. By default the DESCRIPTION file of the current package (i.e. the package the working directory is part of) is used.

Details

By default, the following string is returned if key = "NoRealKey" is not found:

"<No `NoRealKey` field set in DESCRIPTION!>"

If you rather want to take an action like throwing an error, it's recommended to call desc::desc_get_field() directly.

Value

A character scalar.

See Also

Other package DESCRIPTION functions: desc_dep_vrsn(), desc_list(), desc_url_git()

Examples

pal::desc_get_field_safe(key = "Description",
                         file = fs::path_package("pal"))

salim-b/pal documentation built on June 9, 2025, 12:39 a.m.