[Rd] structure(NULL, *) is deprecated [was: Unexpected I(NULL) output]

Martin Maechler maechler at stat.math.ethz.ch
Thu Dec 29 22:32:08 CET 2016


>>>>> Martin Maechler <maechler at stat.math.ethz.ch>
>>>>>     on Thu, 22 Dec 2016 10:24:43 +0100 writes:

>>>>> Florent Angly <florent.angly at gmail.com>
>>>>>     on Tue, 20 Dec 2016 13:42:37 +0100 writes:

    >> Hi all,
    >> I believe there is an issue with passing NULL to the function I().

    >> class(NULL)  # "NULL"  (as expected)
    >> print(NULL)   # NULL  (as expected)
    >> is.null(NULL) # TRUE  (as expected)

    >> According to the documentation I() should return a copy of its input
    >> with class "AsIs" preprended:

    >> class(I(NULL))  # "AsIs"  (as expected)
    >> print(I(NULL))   # list()  (not expected! should be NULL)
    >> is.null(I(NULL)) # FALSE  (not expected! should be TRUE)

    >> So, I() does not behave according to its documentation. 

    > yes.

    >> In R, it is
    >> not possible to give NULL attributes, but I(NULL) attempts to do that
    >> nonetheless, using the structure() function. Probably:
    >> 1/ structure() should not accept NULL as input since the goal of
    >> structure() is to set some attributes, something cannot be done on
    >> NULL.

    > I tend to agree.  However if we gave an error now, I notice that
    > even our own code, e.g., in stats:::formula.default()  would fail.

    > Still, I think we should consider *deprecating*  structure(NULL, *),
    > so it would give a *warning* (and continue working otherwise)
    > (for a while before giving an error a year later).

 [......................]

    > Martin Maechler
    > ETH Zurich

Since svn rev 71841,   structure(NULL, *) now __is__ deprecated
in R-devel, i.e.,

  > structure(NULL, foo = 2)
  list()
  attr(,"foo")
  [1] 2
  Warning message:
  In structure(NULL, foo = 2) :
    Calling 'structure(NULL, *)' is deprecated, as NULL cannot have attributes.
    Consider 'structure(list(), *)' instead.
  > 

A dozen or so CRAN packages now not only give warnings but
partially also  ERRORS in their checks,  which I find strange,
but it may be because of too stringent checks (e.g. checks were
all warnings are turned into errors).

The most prominent packages now giving errors are
data.table and ggplot2,  then also GGally.

Of course, we (the R core team) could make the deprecation even
milder by not giving a warning() but only a message(.) aka
"NOTE";  however, that renders the deprecation process longer and more
complicated (notably for us),  and there is still a few months' time
before this version of R will be released...
and really, as I said,... a new warning should rarely cause
*errors* but rather warnings.

OTOH, some of us have now seen / read on the  R-package-devel  mailing list
that it seems ggplot2 has stopped working correctly (under
R-devel only!) in building packages because of this warning.. 

The current plan is it will eventually, i.e., after the
deprecation period, become an error, so ideally packages are
patched and re-released ASAP.  It's bedtime here now and we will
see tomorrow how to continue.

My current plan is to an e-mail to the package maintainers of CRAN
packages that are affected, at least for those packages that are "easy to find".

Martin Maechler,
ETH Zurich



More information about the R-devel mailing list