pack_desc: List or modify package (description) files

Description Usage Arguments Details Value See Also Examples

View source: R/package.R

Description

pack_desc reads the ‘DESCRIPTION’ file of an R package and makes use of its content in several possible ways. pkg_files lists files within given subdirectories of a package. It works on either installed packages or package source folders. is_pkg_dir determines whether names refer to such package directories.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
  pack_desc(pkg, ...)

  ## S3 method for class 'character'
 pack_desc(pkg,
    action = c("read", "update", "source", "spell"),
    version = TRUE, demo = FALSE,
    date.format = "%Y-%m-%d", envir = globalenv(), ...)

  pkg_files(x, ...)

  ## S3 method for class 'character'
 pkg_files(x, what, installed = TRUE,
    ignore = NULL, ...)

  is_pkg_dir(x)

  ## S3 method for class 'character'
 is_pkg_dir(x)

Arguments

pkg

Name(s) of one to several package directories. The package name alone does not suffice unless the package is a subdirectory of the working directory.

action

Character scalar determining the output mode.

version

Logical scalar. Also update the version? Only relevant if action is ‘update’. Note that this updating would only affect the last part of the version string separated by ‘-’; if this does not exist, it is ignored. Updating is not done if the old date is identical or newer to the new one. Note that this comparison only works properly if data.format is correctly specified.

demo

Logical scalar. Do not update or source files, just return a description of the result?

date.format

Character scalar. The format used and expected for the date of the package.

envir

Environment used when reading the files with source. Only relevant if action is set to ‘source’.

x

Character vector. For pkg_files, if installed is TRUE, the names of installed packages. Otherwise names of package directories, which are expanded automatically, and/or directly the names of files, which may or may not reside within a package. The directory must be recognisable by is_pkg_dir for the expansion to work. For is_pkg_dir, an arbitrary character vector.

what

Character vector. The subdirectories to list.

installed

Logical scalar. If TRUE, the package(s) are searched using find.package. Otherwise pkg is treated as list of directories and/or file names, distinguished using is_pkg_dir.

ignore

NULL or a character vector of file names (without their directory-name parts) to remove from the result, or a list. Ignored if empty. If a non-empty character vector, matching is done case- insensitively. If a list, used as arguments passed to grep (except for x, value and invert). Enclosing ignore in I() reverts the action.

...

Optional arguments passed to and from other methods, or between the methods.

Details

pack_desc optionally sets the ‘Date’ entry to the current date, and if requested increments the subversion number of the package version, if any, and writes the data back to each input file. Alternatively, it calls source on all R code files of a package as listed in the ‘DESCRIPTION’ file. Spell checking is another option.

Value

The value returned by pack_desc depends on the value of action:

read

Object of class pack_descs, basically a nested list with pkg as names. The values are objects of class pack_desc.

source

This loads the R code files of the package(s) using source from the base package in the correct order, and call library on all the package names given under ‘Depends’ and ‘Imports’. Thus a list of source results is obtained, returned invisibly. ... is passed to source if demo is FALSE.

spell

Check the spelling of using aspell and an appropriate filter. This yields an object of class aspell. Package names marked as misspelled, if any, are automatically discarded.

update

One- or two-column character matrix with one row per entry in pkg, showing the updated date and optionally the version string. ... is passed to write.dcf if demo is FALSE.

pkg_files yields a character vector of file names (empty if no such files are found).

is_pkg_dir yields a logical vector with the same length than x.

See Also

base::read.dcf base::write.dcf base::source base::list.files base::find.package base::system.file utils::packageDescription

Other package-functions: check_R_code, check_Sweave_start, copy_pkg_files, delete_o_files, logfile, run_R_CMD, swap_code,

Examples

 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
pkg <- find.package(c("tools", "utils"), quiet = TRUE)

# Reading
(x <- pack_desc(pkg, "read")) # should look similar to packageVersion()
stopifnot(is.list(x), names(x) == pkg, inherits(x, "pack_descs"))
stopifnot(sapply(x, is.list), sapply(x, inherits, what = "pack_desc"))

# Updating (in demo mode, of course)
(x <- pack_desc(pkg, "update", demo = TRUE, date.format = "%Y/%m/%d"))
stopifnot(is.character(x), is.matrix(x), rownames(x) == pkg,
  colnames(x) == c("Date", "Version"))
(x <- pack_desc(pkg, "update", demo = TRUE, version = FALSE))
stopifnot(is.character(x), is.matrix(x), rownames(x) == pkg,
  colnames(x) == "Date")

# Source'ing (in demo mode, of course)
(x <- pack_desc(pkg, "source", demo = TRUE))
stopifnot(is.list(x), names(x) == pkg, sapply(x, is.list))
stopifnot(sapply(x, names) == c("Depends", "Imports", "Collate"))

# See also the 'docu.R' script, options '--format' and '--keep'.

## pkg_files()
pkg <- find.package(c("tools", "utils"), quiet = TRUE)
(x <- pkg_files(pkg, "R"))
stopifnot(is.character(x), length(x) > 0)

## is_pkg_dir()
(x <- is_pkg_dir(c("foo", "bar", "baz")))
stopifnot(!x)
(x <- is_pkg_dir(find.package(c("tools", "utils"), quiet = TRUE)))
stopifnot(x)

pkgutils documentation built on May 2, 2019, 5:49 p.m.

Related to pack_desc in pkgutils...