Re: [R] $ operator is invalid for atomic vectors, returning NULL - what is the right thing to do then?

From: Duncan Murdoch <>
Date: Thu, 06 Dec 2007 09:51:38 -0500

On 12/6/2007 7:04 AM, Søren Højsgaard wrote:
> Dear all,
> Starting from a recent version of R, the $ became "unusable" on atomic vectors, e.g.

>> x <- c(a=1,b=2)
>> x$a

> Warning message:
> In x$a : $ operator is invalid for atomic vectors, returning NULL
> I can of course do
>> x['a']

> - but that requires more typing (5 characters rather than 2).
> Apologies if I've missed a an announcement regarding this, but
> 1) Is there an alternative to the ['a'] and
> 2) Why was this change made?

There's an announcement in the NEWS file for 2.6.0


     o	$ on an atomic vector now gives a warning that it is 'invalid'.
	It remains deprecated, but may be removed in R >= 2.7.0.

and an update in R-devel saying that in fact it has been made defunct there.

In answer to your questions:

  1. I don't think so, other than x[1].
  2. I don't remember the details, other than it was to avoid confusion. Maybe someone else can summarize the discussion?

Duncan Murdoch mailing list PLEASE do read the posting guide and provide commented, minimal, self-contained, reproducible code. Received on Thu 06 Dec 2007 - 14:50:51 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 06 Dec 2007 - 15:30:17 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.