Message-ID: <1c8c09d8979274ab425ae9e48346cd49.squirrel@webmail.xs4all.nl>
Date: 2013-07-04T12:04:47Z
From: Alex van der Spek
Subject: list construction with automatic names
I often find myself (wanting t)o constructing lists or data.frames like so:
#Find files in subdirs
ii <- 0
for (ix in id) {
ii <- ii + 1
if (ii == 1) {
fl <- list(basename(ix) = list.files(ix))
} else {
fl <- c(fl, list(basename(ix) = list.files(ix)))
}
}
The above is for list construction. It does not work as the argument name
is not accepted. In python this would be legal but I can't find how to
modify the name argument in R to make this legal.
Furthermore the use of a separate counter is not very elegant. Would there
be a better way? Again, in python appending to a list is very easy but
seems to be available in R only for vectors not lists?
Any help much appreciated!
Alex van der Spek