Re: [Rd] Unexpected I(NULL) output
Thank you for the feedback, Martin. Of course, deprecating would be a sensible way to go. I filed this issue on BugZilla under # 17198. Florent On 22 December 2016 at 10:24, Martin Maechlerwrote: >> Florent Angly >> 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). > > > 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. > > If we'd adopt 2, the I(.) function would become slightly more > complicated and slower... but possibly not practically > noticeable. > > A last option would be > > 3/ The help page for I() could note what happens in the NULL case. > > That would be the least work for everyone, > but at the moment, I tend to agree that '1/' is worth the pain to > have R's structure() become more consistent. > > Martin Maechler > ETH Zurich > > > 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 > > > __ > > R-devel@r-project.org mailing list > > https://stat.ethz.ch/mailman/listinfo/r-devel __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] Unexpected I(NULL) output
> Florent Angly> 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). > 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. If we'd adopt 2, the I(.) function would become slightly more complicated and slower... but possibly not practically noticeable. A last option would be 3/ The help page for I() could note what happens in the NULL case. That would be the least work for everyone, but at the moment, I tend to agree that '1/' is worth the pain to have R's structure() become more consistent. Martin Maechler ETH Zurich > 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 > __ > R-devel@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
[Rd] Unexpected I(NULL) output
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 __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel