Bug 17422 - install.packages(character(0)) could finish silently
Summary: install.packages(character(0)) could finish silently
Alias: None
Product: R
Classification: Unclassified
Component: Misc (show other bugs)
Version: R-devel (trunk)
Hardware: Other All
: P5 enhancement
Assignee: R-core
Depends on:
Reported: 2018-05-13 10:30 UTC by Jan Gorecki
Modified: 2018-06-01 16:53 UTC (History)
1 user (show)

See Also:

proposed patch for silent install.packages(character(0)) (1.49 KB, patch)
2018-05-13 10:30 UTC, Jan Gorecki
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Jan Gorecki 2018-05-13 10:30:32 UTC
Created attachment 2345 [details]
proposed patch for silent install.packages(character(0))

I would like to propose to change behavior of `install.packages` for `pkgs` argument equal to `character()`.
Currently it will popup list of packages to choose to install. When in non-interactive session it will raise an error.
While such behavior perfectly make sense for `install.packages()` call, it is not that much desired for `install.packages(character(0))` call.
Motivation behind this change is best described by use cases I have seen in some users scripts.

1. procedure to install dependencies which to install only non-installed packages

deps <- c("pkg.a","pkg.b")
inst.pkgs <- rownames(installed.packages())
install.packages(setdiff(deps, inst.pkgs))

currently we have to always add extra check, otherwise our procedure might fail

to.inst.pkgs <- setdiff(deps, inst.pkgs)
if (length(to.inst.pkgs)) install.packages(to.inst.pkgs)

2. function that extracts dependencies from DESCRIPTION file, to install dependencies of arbitrary package based on its sources. Some of packages might not have any dependencies so `character(0)` is returned, then again you have to escape call.

if (length(pkgs<-dcf.dependencies("/path/to/DESCRIPTION"))) install.packages(pkgs)

It would be more friendly if `install.packages(character(0))` would return `invisible()` and not raise `no packages were specified` error as now.

Attaching proposed patch based on recent trunk.
Comment 1 Kurt Hornik 2018-06-01 16:53:43 UTC
Fixed now in the trunk.