From ripley at stats.ox.ac.uk  Mon Jun 23 18:00:28 2003
From: ripley at stats.ox.ac.uk (Prof Brian Ripley)
Date: Mon Jun 23 18:00:36 2003
Subject: [Rd] trace trap (PR#3324)
In-Reply-To: <200306231536.h5NFaHJH026836@pubhealth.ku.dk>
Message-ID: <Pine.LNX.4.44.0306231657310.28305-100000@gannet.stats>

On Mon, 23 Jun 2003 p.e.brown@lancaster.ac.uk wrote:

> Hi.  I wanted to add two new columns to a data frame, and ended up 
> crashing R
> 
>  > temp <- data.frame(a=1:3, b=4:6)
>  > temp[[c("d","e")]] <- NA
> 
> Process R trace trap at Mon Jun 23 16:32:36 2003
> 
> I know the above code isn't very elegent, but it shouldn't crash R.

It's erroneous code, and the current development version of R correctly
reports so.

> I managed to add the new columns doing
> 
>  > temp[,c("d","e")] <- NA

or temp[c("d","e")] <- NA.

Are you sure you know the difference between [] and [[]]?

-- 
Brian D. Ripley,                  ripley@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595


[Rd] trace trap (PR#3324)
Prof Brian Ripley