Bug 17422

Summary: install.packages(character(0)) could finish silently
Product: R Reporter: Jan Gorecki <j.gorecki>
Component: MiscAssignee: R-core <R-core>
Status: CLOSED FIXED    
Severity: enhancement CC: Kurt.Hornik
Priority: P5    
Version: R-devel (trunk)   
Hardware: Other   
OS: All   
Attachments: proposed patch for silent install.packages(character(0))

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.