1

The syntax obj <- {} caught my eye in this post https://stackoverflow.com/a/3417894/168689. I'm fairly new to R and hadn't seen it before so I fired up my console:

obj <- {}
class(obj)

and found an object of class NULL.

class(obj) 
[1] "NULL"

I'd like to know the opinions on this technique in the R community. Is there merit in it? Do the possible downsides (really, no class?) outweigh those?

Community
  • 1
  • 1
Rob
  • 834
  • 1
  • 10
  • 15

1 Answers1

3

{} is equivalent to NULL. Note identical({}, NULL) is TRUE. NULL is clearer, imo, but there are no repercussions to using {} instead---except maybe the risk of inducing momentary confusion on someone reviewing your code.

Matthew Plourde
  • 43,932
  • 7
  • 96
  • 113