In R-patched_2003-10-20, subsetted 1-D arrays no longer get converted to vectors. The NEWS file documents this change, as an indirect result of bug report 4110. I just wanted to mention this can break code in some rather obscure ways, such as this toy example: R> x <- sort(tapply(1:8, rep(1:4,2), sum)) # Was vector, now is 1D array R> y <- matrix(1:4, 1,4) # 1x4 matrix R> x + y # Used to return a 1x4 matrix Error in x + y : non-conformable arrays I agree with the change, but I would beware that some puzzled users may not associate new "tapply problems" with this news item. Also, *should* you be able to add a (4) array to a (1,4) array? -- -- David Brahm (brahm@alum.mit.edu)
David Brahm <brahm@alum.mit.edu> writes:> In R-patched_2003-10-20, subsetted 1-D arrays no longer get converted to > vectors. The NEWS file documents this change, as an indirect result of bug > report 4110. I just wanted to mention this can break code in some rather > obscure ways, such as this toy example: > > R> x <- sort(tapply(1:8, rep(1:4,2), sum)) # Was vector, now is 1D array > R> y <- matrix(1:4, 1,4) # 1x4 matrix > R> x + y # Used to return a 1x4 matrix > Error in x + y : non-conformable arraysWithout the sort() that was an error in 1.8.0 too. However, we've found other surprises like prop.trend.test(tt[1,], margin.table(tt,2)) which internally will pass a 1D array as weights to lm.> I agree with the change, but I would beware that some puzzled users may not > associate new "tapply problems" with this news item.Yep. And I tend to agree that the original problem had to be fixed.> Also, *should* you be able to add a (4) array to a (1,4) array?...or to a (4,1) array? Currently the answer is clearly neither: if both terms have dimensions, the dimensions must match. It is kind of tempting though. -- O__ ---- Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard@biostat.ku.dk) FAX: (+45) 35327907
On Tue, 21 Oct 2003, David Brahm wrote:> In R-patched_2003-10-20, subsetted 1-D arrays no longer get converted to > vectors. The NEWS file documents this change, as an indirect result of bug > report 4110. I just wanted to mention this can break code in some rather > obscure ways, such as this toy example: > > R> x <- sort(tapply(1:8, rep(1:4,2), sum)) # Was vector, now is 1D array > R> y <- matrix(1:4, 1,4) # 1x4 matrix > R> x + y # Used to return a 1x4 matrix > Error in x + y : non-conformable arrays > > I agree with the change, but I would beware that some puzzled users may not > associate new "tapply problems" with this news item.We are aware of a couple of such problems, but they are code that should not have worked before. Unfortunately, in S tapply gives a vector and not a 1D array here ....> Also, *should* you be able to add a (4) array to a (1,4) array?No. You cannot in S. -- 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
Prof Brian Ripley <ripley@stats.ox.ac.uk>> David Brahm <brahm@alum.mit.edu> > > Also, *should* you be able to add a (4) array to a (1,4) array? > No. You cannot in S.You can't in APL or mathematics either. There is a tradeoff between expressiveness and enforcing code quality. The downside of giving meaning to otherwise non-meaningful expressions is that fewer errors can be caught by the system -- its harder for the user to detect a wrong result than to simply respond to an error message. _______________________________________________ No banners. No pop-ups. No kidding. Introducing My Way - http://www.myway.com