[Rd] Using {} for NULL
@vi@e@gross m@iii@g oii gm@ii@com
@vi@e@gross m@iii@g oii gm@ii@com
Sun May 10 19:00:14 CEST 2026
Ah, given that analysis, Hadley, You might as well use:
{{}}
Or even
{{{{{}}}}}
Or, do those not ultimately evaluate as a null-like thing as they are sort of a set of a set of a set of a ...
-----Original Message-----
From: R-devel <r-devel-bounces using r-project.org> On Behalf Of Hadley Wickham
Sent: Sunday, May 10, 2026 9:21 AM
To: Peter Dalgaard <pdalgd using gmail.com>
Cc: r-devel <r-devel using r-project.org>
Subject: Re: [Rd] Using {} for NULL
(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]]
______________________________________________
R-devel using r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
More information about the R-devel
mailing list