knitr::opts_chunk$set( comment = "#>", tidy = FALSE, error = FALSE, fig.width = 8, fig.height = 8)
Parse DESCRIPTION files
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.
source("https://install-github.me/r-lib/desc")
library(desc)
The object oriented API uses R6 classes.
DESCRIPTION
filesA new description
object can be created by reading a DESCRPTION
file form the disk. By default the DESCRIPTION
file in the current
directory is read:
desc <- description$new() desc
A new object can also be created from scratch:
desc2 <- description$new("!new") desc2
DESCRIPTION
filesMost 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.
get()
and set()
queries or updates a field:
desc$set("Package", "foo") desc$get("Package")
They work with multiple fields as well:
desc$set(Package = "bar", Title = "Bar Package") desc$get(c("Package", "Title"))
Package dependencies can be set and updated via an easier API:
desc$get_deps() desc$set_dep("mvtnorm") desc$set_dep("Rcpp", "LinkingTo") desc$get_deps() desc
Collate fields can be queried and set using simple character vectors of file names:
desc$set_collate(list.files("../R")) desc$get_collate()
Authors information, when specified via the Authors@R
field,
also has a simplified API:
desc <- description$new("DESCRIPTION2") desc$get_authors() desc$add_author("Bugs", "Bunny", email = "bb@acme.com") desc$add_me() desc$get_authors()
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_set_dep("newpackage", "Suggests")
This added newpackage
to the Suggests
field:
desc_get("Suggests")
So the full list of dependencies are now
desc_get_deps()
MIT © Gábor Csárdi, RStudio Inc
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.