This function is similar to utils::installed.packages()
.
See the differences below.
Usage
parse_installed(
library = .libPaths(),
priority = NULL,
lowercase = FALSE,
reencode = TRUE,
packages = NULL
)
Arguments
- library
Character vector of library paths.
- priority
If not
NULL
then it may be a"base"
"recommended"
NA
or a vector of these to select base packages, recommended packages or other packages. (These are the official, CRAN supported package priorities, but you may introduce others in non-CRAN packages.)- lowercase
Whether to convert keys in
DESCRIPTION
to lowercase.- reencode
Whether to re-encode strings in UTF-8, from the encodings specified in the
DESCRIPTION
files. Re-encoding is somewhat costly, and sometimes it is not important (e.g. when you only want to extract the dependencies of the installed packages).- packages
If not
NULL
, then it must be a character vector, and only these packages will be listed.
Details
Differences with utils::installed.packages()
:
parse_installed()
cannot subset the extracted fields. (But you can subset the result.)parse_installed()
does not cache the results.parse_installed()
handles errors better. See Section 'Errors' below. #' *parse_installed()
uses theDESCRIPTION
files in the installed packages instead of theMeta/package.rds
files. This should not matter, but because of a bugMeta/package.rds
might contain the wrongArchs
field on multi-arch platforms.parse_installed()
reads all fields from theDESCRIPTION
files.utils::installed.packages()
only reads the specified fields.parse_installed()
converts its output to UTF-8 encoding, from the encodings declared in theDESCRIPTION
files.parse_installed()
is considerably faster.
Encodings
parse_installed()
always returns its result in UTF-8 encoding.
It uses the Encoding
fields in the DESCRIPTION
files to learn their
encodings. parse_installed()
does not check that an UTF-8 file has a
valid encoding. If it fails to convert a string to UTF-8 from another
declared encoding, then it leaves it as "bytes"
encoded, without a
warning.
Errors
pkgcache silently ignores files and directories inside the library directory.
The result also omits broken package installations. These include
packages with invalid
DESCRIPTION
files, andpackages the current user have no access to.
These errors are reported via a condition with class
pkgcache_broken_install
. The condition has an errors
entry, which
is a data frame with columns
file
: path to theDESCRIPTION
file of the broken package,error
: error message for this particular failure.
If you intend to handle broken package installation, you need to catch
this condition with withCallingHandlers()
.