Parse, manipulate and reformat DESCRIPTION files. The package provides
two APIs, one is object oriented, the other one is procedural and
manipulates the files in place.
# Install the released version from CRAN
install.packages("desc")
# Or the development version from GitHub:
# install.packages("pak")
pak::pak("r-lib/desc")
Most DESCRIPTION fields may be formatted in multiple equivalent ways.
desc does not reformat fields, unless they are updated or reformatting
is explicitly requested via a call to the normalize() method or using
the normalize argument of the write() method.
Querying, changing and removing fields
get() and set() queries or updates a field:
desc$set("Package", "foo")
desc$get("Package")
#> Package
#> "foo"
They work with multiple fields as well:
desc$set(Package = "bar", Title = "Bar Package")
desc$get(c("Package", "Title"))
#> Package Title
#> "bar" "Bar Package"
Dependencies
Package dependencies can be set and updated via an easier API:
If the Author field is specified, it can be changed to a Authors@R
field using coerce_authors_at_r(), incorporating the Maintainer
information if necessary:
#> Error in ensure_authors_at_r(self): No 'Authors@R' field!
#> You can create one with $add_author.
#> You can also use $coerce_authors_at_r() to change Author fields
The procedural API is simpler to use for one-off DESCRIPTION
manipulation, since it does not require dealing with description
objects. Each object oriented method has a procedural counterpart that
works on a file, and potentially writes its result back to the same
file.
For example, adding a new dependency to DESCRIPTION in the current
working directory can be done with
desc
Parse, manipulate and reformat DESCRIPTION files. The package provides two APIs, one is object oriented, the other one is procedural and manipulates the files in place.
DESCRIPTIONfilesDESCRIPTIONfilesInstallation
The object oriented API
Introduction
The object oriented API uses R6 classes.
Loading or creating new
DESCRIPTIONfilesA new
descriptionobject can be created by reading aDESCRIPTIONfile form the disk. By default theDESCRIPTIONfile in the current directory is read:A new object can also be created from scratch:
Normalizing
DESCRIPTIONfilesMost
DESCRIPTIONfields may be formatted in multiple equivalent ways.descdoes not reformat fields, unless they are updated or reformatting is explicitly requested via a call to thenormalize()method or using thenormalizeargument of thewrite()method.Querying, changing and removing fields
get()andset()queries or updates a field:They work with multiple fields as well:
Dependencies
Package dependencies can be set and updated via an easier API:
Collate fields
Collate fields can be queried and set using simple character vectors of file names:
Authors
Authors information, when specified via the
Authors@Rfield, also has a simplified API:If the
Authorfield is specified, it can be changed to aAuthors@Rfield usingcoerce_authors_at_r(), incorporating theMaintainerinformation if necessary:The procedural API
The procedural API is simpler to use for one-off
DESCRIPTIONmanipulation, since it does not require dealing withdescriptionobjects. Each object oriented method has a procedural counterpart that works on a file, and potentially writes its result back to the same file.For example, adding a new dependency to
DESCRIPTIONin the current working directory can be done withThis added
newpackageto theSuggestsfield:So the full list of dependencies are now
Code of Conduct
Please note that the desc project is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms.