Bug 17453 - R CMD INSTALL explicitly sets `options(warn = 1)`, which prevents other settings (such as `options(warn = 2)`)
Summary: R CMD INSTALL explicitly sets `options(warn = 1)`, which prevents other setti...
Alias: None
Product: R
Classification: Unclassified
Component: Installation (show other bugs)
Version: R 3.5.0
Hardware: All All
: P5 normal
Assignee: R-core
Depends on:
Reported: 2018-08-17 18:24 UTC by Jim Hester
Modified: 2018-08-20 13:51 UTC (History)
1 user (show)

See Also:


Note You need to log in before you can comment on or make changes to this bug.
Description Jim Hester 2018-08-17 18:24:48 UTC
In line 151 of src/library/tools/R/install.R there is a call to `options(warn = 1)`. This means it is not possible to set `options(warn = 2)` e.g. in a user or site `.RProfile` and have it change the warnings from `R CMD install` to errors.

Changing these to errors would be beneficial on Windows in particular, as commonly people try to install packages with shared libraries which are already loaded either in the current R process or another R process. When this happens copying the dll fails (with a warning) and the users library is left with a broken package. It would be useful to change this warning to an error in this case, so it is more apparent that something went wrong during the installation. Some example issues where this has been reported are https://github.com/rstudio/rstudio/issues/2070, https://github.com/rstudio/rstudio/issues/3022, https://github.com/r-lib/remotes/issues/113 although there are plenty of other examples as well.

The following patch simply removes this line. An alternative approach would be to provide an additional option to `R CMD INSTALL` that would allow you to control this behavior.

Index: src/library/tools/R/install.R
--- src/library/tools/R/install.R	(revision 74948)
+++ src/library/tools/R/install.R	(working copy)
@@ -148,7 +148,6 @@
                              perl = TRUE))
-    options(warn = 1)
     invisible(Sys.setlocale("LC_COLLATE", "C")) # discard output
     if (WINDOWS) {
Comment 1 Martin Maechler 2018-08-18 12:23:24 UTC
Thank you, Jim.

This is not good indeed.  OTOH,  warn=1 is there for a reason.. also for debugging. Just canceling it is clearly not desired.

But of course the current way is undesirable.
Notably, as this is the hidden-for-the-expert function .install_packages()  which is occasionally used outside 'R CMD INSTALL', and no longer always calls q() at the end, the warn option should also not last beyond the scope.

I've decided to take the most flexible approach:
With the general goal to go for functional programming, I'll make it into an argument with default '1' *and* only set it when the current warning level is lower... so it will never overrule a  'warn=2' seting.
Comment 2 Martin Maechler 2018-08-18 13:03:19 UTC
Comitted as svn rev 75166  (for R-devel).

Planned to be ported to R 3.5.1 patched.
Comment 3 Jim Hester 2018-08-20 13:51:19 UTC
Thanks Martin!