Skip to content

Commit a39f4a2

Browse files
author
maechler
committed
activate options(warn = <val>) checking (after > 6 years "not yet") via \env{R_WARN_BOUNDS_OPT}
git-svn-id: https://svn.r-project.org/R/trunk@89337 00db46b3-68df-0310-9c12-caf00c1e9a41
1 parent 3396d4c commit a39f4a2

File tree

3 files changed

+20
-13
lines changed

3 files changed

+20
-13
lines changed

doc/NEWS.Rd

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,10 @@
176176

177177
\item Error messages from failed Rd \verb{\Sexpr} code now include
178178
the call from the original condition (if available).
179+
180+
\item When the environment variable \env{R_WARN_BOUNDS_OPT} is set to
181+
\code{"yes"}, \code{options(warn = val)} will check if \code{val} is
182+
inside \code{-1:2}; this may happen unconditionally in the future.
179183
}
180184
}
181185

@@ -520,9 +524,6 @@
520524
\item On Windows terminals \kbd{Ctrl-C} now breaks out of waiting for
521525
keyboard input, fixing \PR{18982}.
522526

523-
\item \code{pretty(ch)} again correctly works with \code{ch} a
524-
character vector of numbers.
525-
526527
\item The default \code{summary()} and its factor method now
527528
label missing values \samp{NAs} rather than \samp{NA's},
528529
fixing a decades-old grammatical faux pas inherited from S
@@ -577,7 +578,10 @@
577578
thanks to \I{Leo Mada} and other \I{\dQuote{R-help}ers}.
578579
579580
\item \code{vignette(\var{pkg}::\var{topic})} is now a documented
580-
usage variant and confines vignette retrieval to the specified package.
581+
usage variant and confines vignette retrieval to the specified package.
582+
583+
\item \code{pretty(ch)} again correctly works with \code{ch} a
584+
character vector of numbers.
581585
}
582586
}
583587
}

src/library/base/man/options.Rd

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
% File src/library/base/man/options.Rd
22
% Part of the R package, https://www.R-project.org
3-
% Copyright 1995-2025 R Core Team
3+
% Copyright 1995-2026 R Core Team
44
% Distributed under GPL 2 or later
55

66
\name{options}
@@ -456,16 +456,19 @@ getOption(x, default = NULL)
456456
\option{--verbose}.}
457457

458458
\item{\code{warn}:}{integer value to set the handling of warning
459-
messages by the default warning handler. If
460-
\code{warn} is negative all warnings are ignored. If \code{warn}
459+
messages by the default warning handler. In the future, this value
460+
is checked to be one of \code{-1, 0, 1, 2}. For now, setting
461+
environment variable \env{R_WARN_BOUNDS_OPT} to \code{"yes"}
462+
activates that check.
463+
If \code{warn} is negative all warnings are ignored. If \code{warn}
461464
is zero (the default) warnings are stored until the top--level
462465
function returns. If 10 or fewer warnings were signalled they
463466
will be printed otherwise a message saying how many were
464467
signalled. An object called \code{last.warning} is
465468
created and can be printed through the function
466469
\code{\link{warnings}}. If \code{warn} is one, warnings are
467470
printed as they occur. If \code{warn} is two (or larger, coercible
468-
to integer), all warnings are turned into errors. While sometimes
471+
to integer), all warnings are turned into errors. While sometimes
469472
useful for debugging, turning warnings into errors may trigger
470473
bugs and resource leaks that would not have been triggered otherwise.}
471474

src/main/options.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* R : A Computer Language for Statistical Data Analysis
3-
* Copyright (C) 1998-2025 The R Core Team.
3+
* Copyright (C) 1998-2026 The R Core Team.
44
* Copyright (C) 1995, 1996 Robert Gentleman and Ross Ihaka
55
*
66
* This program is free software; you can redistribute it and/or modify
@@ -685,11 +685,11 @@ attribute_hidden SEXP do_options(SEXP call, SEXP op, SEXP args, SEXP rho)
685685
}
686686
if (k == NA_INTEGER)
687687
error(_("invalid value for '%s'"), CHAR(namei));
688-
#ifdef _NOT_YET_
688+
#ifndef _ALLOW_WARN_OUT_OF_BOUNDS_OPT_
689689
char *p = getenv("R_WARN_BOUNDS_OPT");
690690
if ((p && (strcmp(p, "yes") == 0)) && (k < -1 || k > 2)) {
691691
int k_n = (k < 0) ? -1 : 2;
692-
REprintf(_("value for '%s' outside of -1:2 is set to %d\n"),
692+
warning(_("value for '%s' outside of -1:2 is set to %d\n"),
693693
CHAR(namei), k_n);
694694
k = k_n;
695695
}
@@ -894,7 +894,7 @@ attribute_hidden SEXP do_options(SEXP call, SEXP op, SEXP args, SEXP rho)
894894
if (TYPEOF(argi) != LGLSXP || LENGTH(argi) != 1)
895895
error(_("invalid value for '%s'"), CHAR(namei));
896896
Rboolean k = asRbool(argi, call);
897-
#ifdef NO_QUIET_AND_VERBOSE
897+
#ifdef NO_QUIET_AND_VERBOSE
898898
if(k && R_Verbose)
899899
error(_("cannot set both options 'quiet' and 'verbose' to TRUE"));
900900
#endif
@@ -905,7 +905,7 @@ attribute_hidden SEXP do_options(SEXP call, SEXP op, SEXP args, SEXP rho)
905905
if (TYPEOF(argi) != LGLSXP || LENGTH(argi) != 1)
906906
error(_("invalid value for '%s'"), CHAR(namei));
907907
Rboolean k = asRbool(argi, call);
908-
#ifdef NO_QUIET_AND_VERBOSE
908+
#ifdef NO_QUIET_AND_VERBOSE
909909
if(k && R_Quiet)
910910
error(_("cannot set both options 'quiet' and 'verbose' to TRUE"));
911911
#endif

0 commit comments

Comments
 (0)