[Rd] Using {} for NULL
Hadley Wickham
h@w|ckh@m @end|ng |rom gm@||@com
Sun May 10 15:21:16 CEST 2026
(Not serious)
bench::system_time({}) suggests that it takes ~10µs to evaluate {}.
Assuming you type at 100 wpm, i.e. 500 characters per minute, that's 8.33
characters per second, or 120 ms per letter, you save 240 ms by typing {}
instead of NULL, therefore you'd need to evaluate {} 24,000 times to make
the savings worth it :)
Hadley
On Mon, May 4, 2026 at 8:46 AM Peter Dalgaard <pdalgd using gmail.com> wrote:
> On the contrary: NULL is a constant, {} is an expression, which needs to
> be evaluated before you know its value. And, considering lazy evaluation
> and all that, I wouldn't bet on the compiler to optimize the difference
> away.
>
> -pd
>
> > On 30 Apr 2026, at 11.42, Duncan Murdoch <murdoch.duncan using gmail.com>
> wrote:
> >
> > The news item for a recent R-devel bug fix says this:
> >
> > - ‘cut(1:11, {})’ now signals an error for the invalid ‘breaks’, fixing
> PR#19057, thanks to Kevin Ushey.
> >
> > When I read that, I wondered why {} was used. Does it give some weird
> exotic object? No, its value is NULL, which was used in the referenced bug
> report.
> >
> > So my question is: why use {} instead of NULL in an expression? I
> don't think there are any efficiency advantages.
> >
> > Duncan Murdoch
> >
> > ______________________________________________
> > R-devel using r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-devel
>
> --
> Peter Dalgaard, Professor,
> Center for Statistics, Copenhagen Business School
> Solbjerg Plads 3, 2000 Frederiksberg, Denmark
> Phone: (+45)38153501
> Office: A 4.23
> Email: pd.mes using cbs.dk Priv: PDalgd using gmail.com
>
> ______________________________________________
> R-devel using r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>
--
http://hadley.nz
[[alternative HTML version deleted]]
More information about the R-devel
mailing list