How to tell lapply to ignore an error and process the next thing in the list?

Use a tryCatch expression around the function that can throw the error message: testFunction <- function (date_in) { return(tryCatch(as.Date(date_in), error=function(e) NULL)) } The nice thing about the tryCatch function is that you can decide what to do in the case of an error (in this case, return NULL). > lapply(dates2, testFunction) [[1]] [1] “2010-04-06” [[2]] … Read more

lapply-ing with the “$” function

This is documented in ?lapply, in the “Note” section (emphasis mine): For historical reasons, the calls created by lapply are unevaluated, and code has been written (e.g. bquote) that relies on this. This means that the recorded call is always of the form FUN(X[[0L]], …), with 0L replaced by the current integer index. This is … Read more

How to index an element of a list object in R

Indexing a list is done using double bracket, i.e. hypo_list[[1]] (e.g. have a look here: http://www.r-tutor.com/r-introduction/list). BTW: read.table does not return a table but a dataframe (see value section in ?read.table). So you will have a list of dataframes, rather than a list of table objects. The principal mechanism is identical for tables and dataframes … Read more