Skip to content

Querying from R if '--quiet' had been set

4 messages · Martin Maechler, Dirk Eddelbuettel

#
The interactive() predicate is helpful in scripted environments. I sometimes
also invoke R with '--quiet' and am unable to suppress messages from my own
startup code as I cannot test if this flag was set or not. (I can work around
it by setting an additional environment variable, but that is clunky.) For me
'--quiet' is independent to 'interactive'.

R carries the state internally in the integer variable R_Quiet, so a minimal
patch only needs to expose an accessor 'quiet()' model after 'interactive()'.
Then we get the desired behaviour:

  ~/svn/r-devel$ RD -q
  > quiet()
  [1] TRUE
  > 

and this is similarly FALSE in a normal startup without '-q'.

Would this change be of interest?  The patch is just a few lines (but does
not yet contain Rd file changes).

Cheers, Dirk
#
> The interactive() predicate is helpful in scripted environments. I sometimes
    > also invoke R with '--quiet' and am unable to suppress messages from my own
    > startup code as I cannot test if this flag was set or not. (I can work around
    > it by setting an additional environment variable, but that is clunky.) For me
    > '--quiet' is independent to 'interactive'.

    > R carries the state internally in the integer variable R_Quiet, so a minimal
    > patch only needs to expose an accessor 'quiet()' model after 'interactive()'.
    > Then we get the desired behaviour:

    > ~/svn/r-devel$ RD -q
    >> quiet()
    > [1] TRUE
    >> 

    > and this is similarly FALSE in a normal startup without '-q'.

    > Would this change be of interest?  The patch is just a few lines (but does
    > not yet contain Rd file changes).

As Duncan Murdoch recently explained "here" (in the R mailinglists-verse),
this is indeed a change that only R-core could do .. and I agree
that the change would be relatively small, or rather that most of
the work here would be writing / updating documentation, NEWS, etc.

On the other hand, this functionality has been "implicitly" in R, forever :

  > "--quiet" %in% commandArgs()
  [1] FALSE

... though I agree that using commandArgs() looks a bit "clunky"
and may not always do the expected thing  (embedded use of R;  R
Studio / Positron / ....).

What do you think?

Best,
Martin

    > Cheers, Dirk

    > -- 
    > dirk.eddelbuettel.com | @eddelbuettel | edd at debian.org
#
On 27 June 2025 at 17:21, Martin Maechler wrote:
| >>>>> Dirk Eddelbuettel 
| >>>>>     on Fri, 27 Jun 2025 09:22:36 -0500 writes:
| 
|     > The interactive() predicate is helpful in scripted environments. I sometimes
|     > also invoke R with '--quiet' and am unable to suppress messages from my own
|     > startup code as I cannot test if this flag was set or not. (I can work around
|     > it by setting an additional environment variable, but that is clunky.) For me
|     > '--quiet' is independent to 'interactive'.
| 
|     > R carries the state internally in the integer variable R_Quiet, so a minimal
|     > patch only needs to expose an accessor 'quiet()' model after 'interactive()'.
|     > Then we get the desired behaviour:
| 
|     > ~/svn/r-devel$ RD -q
|     >> quiet()
|     > [1] TRUE
|     >> 
| 
|     > and this is similarly FALSE in a normal startup without '-q'.
| 
|     > Would this change be of interest?  The patch is just a few lines (but does
|     > not yet contain Rd file changes).
| 
| As Duncan Murdoch recently explained "here" (in the R mailinglists-verse),
| this is indeed a change that only R-core could do .. and I agree

Rest assured that I am aware of that.

| that the change would be relatively small, or rather that most of
| the work here would be writing / updating documentation, NEWS, etc.
| 
| On the other hand, this functionality has been "implicitly" in R, forever :
| 
|   > "--quiet" %in% commandArgs()
|   [1] FALSE

Ah. Had not thought of that. I could wrap that in a one-line function or use
it directly. 

But not, it doesn't actually work for the '-q | --quiet' equivalence so we
would have to test both which is twice as clunky:

  ~/git/rcpp(feature/release_1.1.0)$ RD -q
  > "--quiet" %in% commandArgs()
  [1] FALSE
  > quiet()
  [1] TRUE
  > 

| ... though I agree that using commandArgs() looks a bit "clunky"

Yes. Especially in "doubled-up use" for '-q' and '--quiet'.

| and may not always do the expected thing  (embedded use of R;  R
| Studio / Positron / ....).
| 
| What do you think?

Well I *wrote* the patch.

I wrote the email to gauge if someone from R Core would consider the patch.

So "what do you think" ?

Cheers, Dirk
 
| Best,
| Martin
| 
|     > Cheers, Dirk
| 
|     > -- 
|     > dirk.eddelbuettel.com | @eddelbuettel | edd at debian.org
#
Thanks to Martin for additional off-list discussion; this is now addressed
'both ways' as I did file bug report #18913 with the short patch but also
have a short check in .Rprofile serving the same purpose:

    ## interactive sessions get a fortune cookie (needs fortunes package)
    quiet <- any(!is.na(match(c("-q", "--quiet"), commandArgs())))
    if (interactive() && !quiet && requireNamespace("fortunes", quietly=TRUE))
        print(fortunes::fortune())

This could be made a little better with #18913 to provide quiet() but already
works.  Now, when I use '-q' in startup no fortune is shown as desired.

Cheers, Dirk