[R] is.null(mylist) and is.null(mylist$a) returns different values
wdunlap at tibco.com
Thu Jun 15 18:19:47 CEST 2017
By the way, NULL is not a "null list", it has class (and type and mode)
"NULL" not "list". "NULL" is an odd class, in that it can have only one
instance and hence can never have any attributes. "list" objects, like
other vector objects, may have length zero, but such objects are not the
same as NULL.
On Thu, Jun 15, 2017 at 8:56 AM, Jeff Newmiller <jdnewmil at dcn.davis.ca.us>
> I find that the str function is more helpful for understanding the
> difference between a null list and a list containing a null list than the
> implicit print function call that the interpreter invokes when you enter an
> expression at the console.
> str( mylist )
> Sent from my phone. Please excuse my brevity.
> On June 15, 2017 8:39:47 AM PDT, Huzefa Khalil <huzefa.khalil at umich.edu>
> >> is.null(mylist[])
> > TRUE
> >Notice the double square brackets.
> >From: ?`[`
> >"The most important distinction between [, [[ and $ is that the [ can
> >select more than one element whereas the other two select a single
> >On Thu, Jun 15, 2017 at 11:33 AM, ce <zadig_1 at excite.com> wrote:
> >> Hi
> >> I have a list :
> >> mylist <- list( a = NULL, b = 1, c = 2 )
> >>> mylist
> >> $a
> >> NULL
> >>> is.null(mylist)
> >>  FALSE
> >>> is.null(mylist$a)
> >>  TRUE
> >> why? I need to use mylist
> >> ______________________________________________
> >> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> >> https://stat.ethz.ch/mailman/listinfo/r-help
> >> PLEASE do read the posting guide
> >> and provide commented, minimal, self-contained, reproducible code.
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> PLEASE do read the posting guide http://www.R-project.org/
> and provide commented, minimal, self-contained, reproducible code.
[[alternative HTML version deleted]]
More information about the R-help