[R] Change in how R handles assignments?
Prof Brian Ripley
ripley at stats.ox.ac.uk
Mon May 17 21:54:58 CEST 2004
On Mon, 17 May 2004, David Kreil wrote:
>
> Dear Prof Brian Ripley,
>
> Thank you very much for your fast and helpful answer!
>
>
> > > I have been using the following code in earlier versions of R:
> >
> > What `earlier versions'? As far as I know this was changed in 1.8.0.
>
> Yes, that fits my observations. We have an old 1.7.1-beta installation
> and a newer 1.8.1; the "old" code runs on the 1.7.1 but not on the
> 1.8.1.
1.9.0 is current, and R-patched (will become 1.9.1 is a few weeks) is
already available with this patched. 1.8.1 is `an earlier version'
already.
> > > q[,names(info)]<-info[no,];
> > You do not need to terminate lines in ;, BTW.
> Thanks! A "bad" C-habit, I suppose.
>
> > But that was not what was documented. The intention is that the rhs be a
> > list, not a data frame.
>
> Ah! Is
> q[,names(info)]<-c(info[no,]);
> a good way of writing it then? It seems to work.
>
>
> > You can do
> > x[, names(info)] <- unclass(info[1, ])
>
> Great, thanks! Is there any advantage of using unclass() vs c()?
c() works only for a single row and columns of the same type. unclass
always works, as a list is the specified value in the docs.
> > We'll unclass a data frame rhs internally in future.
>
> Does that mean that the "old" 1.7.1 code will work again in future R
> releases? That would save me from fixing quite a number of our R
> programs (we'd stick to the 1.7.1 with the old code in the mean time).
I don't know. It means that using a data frame as the rhs with the wrong
number of rows will again recycle each column. Lots of things used to
`work' pre-1.8.0, but were undocumented and not as people expected, often
resulting in corrupted data frames.
--
Brian D. Ripley, ripley at 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
More information about the R-help
mailing list