Skip to content
Prev 343866 / 398498 Next

some question about vector[-NULL]

On 10/09/2014, 3:21 AM, PO SU wrote:
You can do it using

a <- list(ress = 1, res = NULL)
That's a little harder.  There are a few ways:

"res" %in% names(a) & is.null(a[["res"]])

or

identical(a["res"], list(res = NULL))

or

is.null(a[[2]])

should all work.

Generally because of the special handling needed, it's a bad idea to try
to store NULL in a list.
Using !, and a logical test, e.g.

a[!nullentry(a)]

where nullentry() is a function based on one of the tests above, but
applied to all entries.

Duncan Murdoch