Skip to contents

A robust helper for extracting fields from a desc::desc object that gracefully handles missing or undefined entries. Unlike the raw desc$get() method, this function returns NULL instead of a named character vector with NA when a field does not exist.

Usage

get_desc_field(desc, field)

Arguments

desc

A desc::desc object (from the desc package).

field

Character. The name of the field to extract from the DESCRIPTION file.

Value

A scalar character string if the field exists and is not NA, otherwise NULL.

Details

This prevents issues where missing DESCRIPTION fields appear as "NA" strings or one-element named vectors (e.g. field_name = NA), ensuring cleaner downstream assignments in project initialization.

Examples

if (FALSE) { # \dontrun{
d <- desc::desc("DESCRIPTION")
get_desc_field(d, "Title")
get_desc_field(d, "NonexistentField")  # returns NULL
} # }