Here is an ugly hack.
mypath <- 'a/b/c/d' makelist <- function(filepath, fsep = '/'){ unlisted <- unlist(strsplit(filepath, fsep)) nsubs <- length(unlisted) mylistcall <- paste(paste(rep('list(', nsubs), unlisted, collapse = '='), '= NULL', paste(rep(')', nsubs), collapse = '')) mylist <- eval(parse(text = mylistcall)) return(mylist) } makelist(mypath) $a $a$b $a$b$c $a$b$c$d NULL
Remembering
fortune(106) If the answer is parse() you should usually rethink the question. -- Thomas Lumley R-help (February 2005)
In this case, however, I would say that I must reconsider the answer.
mnel
source share