[Rd] Unexpected I(NULL) output
Florent Angly
florent.angly at gmail.com
Tue Dec 20 13:42:37 CET 2016
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. 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.
2/ I() could accept NULL, but, as an exception, not set an "AsIs"
class attribute on it. This would be in line with the philosophy of
the I() function to return an object that is functionally equivalent
to the input object.
My sessionInfo() returns:
> sessionInfo()
R version 3.3.2 (2016-10-31)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1
locale:
[1] LC_COLLATE=German_Switzerland.1252
LC_CTYPE=German_Switzerland.1252
LC_MONETARY=German_Switzerland.1252 LC_NUMERIC=C
[5] LC_TIME=German_Switzerland.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
Best regards,
Florent
More information about the R-devel
mailing list