Skip to content
Prev 60946 / 63424 Next

Should invisible() get signature x=NULL?

> On 01/08/2022 6:27 p.m., Michael Chirico via R-devel
> wrote:
>> I think most experienced R users are familiar with
    >> return(invisible()) being used as shorthand for
    >> return(invisible(NULL)).

    > I'm not sure that's true... the R sources themselves are
    > inconsistent about using invisible() vs invisible(NULL).

Well, they *are* identical in what they return, but to me there *is* a
stylistic difference:  The latter emphasizes the return value to
be NULL.

    >> However, this NULL default is not documented anywhere --
    >> we have to dive into src/main/print.c:do_invisible to
    >> source this behavior.
    >> 
    >> Is this lack of documentation intentional? Otherwise,
    >> should the signature be updated to reflect this default?
    >> 
    >> invisible <- function(x = NULL) .Primitive("invisible")
    >> 
    >> Otherwise, should this default be mentioned in ?invisible
    >> ?

    > But documenting it seems wise.

    > Duncan Murdoch

I prefer to agree with Michael that the "fake" argument list (*)
should be updated to 'x = NULL'.

*) Primitive functions have no formal arguments.  We have
 provided artificially constructed formal arguments mainly for
 printing, only "relatively recently".
 E.g., in R 2.0.0, we still had
.Primitive("invisible")


Martin

--
Martin Maechler
ETH Zurich  and  R Core team