anaximander@gmx.de
2003-Oct-09 22:33 UTC
[Rd] Recursive indexing can cause R-1.8.0 (and R-1.7.1) to segment fault (PR#4486)
Recursive indexing can cause R-1.8.0 (and R-1.7.1) to segment fault First of all, many thanks to the R team!! R is really a software for everyday work. Yes, I've found a fault, but I hope it's not just faultfinding ;-) In the NEWS file of R-1.8.0, first printed in R NEWS 1.7.1, there was given a promise: [ 1 ] o Recursive indexing of lists is allowed, so x[[c(4,2)]] is shorthand for x[[4]][[2]] etc. (Wishlist PR#1588) That's not fulfilled in all cases, although there was already a code correction in R-1.8.0: [ 2 ] o Recursive indexing of lists had too little error-checking. (related to PR#3324) Recursive indexing can cause R-1.8.0 / R-1.7.1 / R-1.7.0 (operating system: linux, compiler: gcc 3.3.1 or 2.95.3) to produce a segment fault. Suppose we have the following code: (be aware: it crashes R!) ################################################################### # R code from Volkmar Klatt, email: volkmar.klatt AT stud.uni-bayreuth.de # just make a nested list: erzeugeTestListe <- function( laenge ) { Liste <- list() for (i in 1: laenge ) { hilf <- round(runif(1)*20) +1 X <- runif( hilf ) Y <- runif( hilf )^2 summeX <- sum(X) summeY <- sum(Y) Liste <- c(Liste, list(list( summe=list(X=summeX, Y=summeY), punkte=list(X=X, Y=Y))) ) } # make clean: rm( hilf, summeX, summeY, X,Y, i ) return( Liste ) } # end of erzeugeTestListe() # # Liste <- erzeugeTestListe(25) #0 # # Now, e.g., we want to extract all X-und Y-elements of Nr. 7-12 and 18,20 # and to write them into a vector A: A <- Liste[[ c(7:12,18,20) ]]$summe$X #1 ...good bye!! # # # __ # //##) # // o - Wow, # / \ fantastic, that's really a short R-session ... # ################################################################### ## ## We can achieve the same result with lapply: # x <- c( 7:12, 18,20 ) # lapply( Liste[[ c(x,1) ]] , FUN=print ) #2 ...good bye! # # # Remark: # Very seldom, R-1.8.0 does not crash, but gives the following # output: # Error: recursive indexing failed at level 3 # You then should just make an other list Liste (line #0) # and try line (#1) or (#2) again. ################################################################### Of coarse, R is not intended to be an ingenious data base program, which should be able to handle, let's say, complicated requests like they are possible in SQL-language. On the other side, lists are becoming more and more important in R, so there *should* be a convenient way to deal with nested lists, shan't it? Sure, all of us can avoid such lists in our own data, but we often have to use data files from other people with *have* a nested structure. (Thats the way I discovered this error.) Perhaps we can find a fair compromise? Have a nice day, Volkmar Klatt anaximander AT gmx.de or volkmar.klatt AT stud.uni-bayreuth.de Bibliography: [ 1 ] http://www.cran.r-project.org/src/base/NEWS , line 1116 f. [ 2 ] ibidem, line 774 f. ########################################################################### -- NEU FÜR ALLE - GMX MediaCenter - für Fotos, Musik, Dateien... Fotoalbum, File Sharing, MMS, Multimedia-Gruß, GMX FotoService Jetzt kostenlos anmelden unter http://www.gmx.net +++ GMX - die erste Adresse für Mail, Message, More! +++
Prof Brian Ripley
2003-Oct-18 17:04 UTC
[Rd] Recursive indexing can cause R-1.8.0 (and R-1.7.1) to segment fault (PR#4486)
On Thu, 9 Oct 2003 anaximander@gmx.de wrote:> Recursive indexing can cause R-1.8.0 (and R-1.7.1) to segment fault > > First of all, many thanks to the R team!! > R is really a software for everyday work. > Yes, I've found a fault, but I hope it's not just faultfinding ;-) > > In the NEWS file of R-1.8.0, first printed in R NEWS 1.7.1, > there was given a promise: [ 1 ] > o Recursive indexing of lists is allowed, so x[[c(4,2)]] is > shorthand for x[[4]][[2]] etc. (Wishlist PR#1588) > > That's not fulfilled in all cases, although there was already a > code correction in R-1.8.0: [ 2 ] > o Recursive indexing of lists had too little error-checking. > (related to PR#3324)That's not a code correction, that's catching unanticipated user errors. This report is also user error which is not always caught. However, please don't say that something has `not been fulfilled' when it works exactly as documented but punishes misuse too severely. It really is hard to anticipate just how silly users can be.> Of coarse, R is not intended to be an ingenious data base program, > which should be able to handle, let's say, complicated requests > like they are possible in SQL-language. > > On the other side, lists are becoming more and more important in R, > so there *should* be a convenient way to deal with nested lists, shan't it? > Sure, all of us can avoid such lists in our own data, but we often > have to use data files from other people with *have* a nested structure. > (Thats the way I discovered this error.)> Perhaps we can find a fair compromise?Yes, would you please not making sweeping statements about R's abilities based on its not failing to cope with your own particular errors? It did report a correct error message at least once! -- 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
Maybe Matching Threads
- "\0" gives no warning "unknown escape sequence" (PR#11107)
- "\0" gives no warning "unknown escape sequence" (PR#11117)
- Bugs compiling R-1.7.1 with Intel compilers icc and ifc (PR#4295)
- Recursive indexing can cause R-1.8.0 (and R-1.7.1) to (PR#4647)
- namespace