[datatable-help] subset between data.table list and single data.table object

Steve Lianoglou mailinglist.honeypot at gmail.com
Wed Aug 7 19:03:32 CEST 2013


Hi,

On Wed, Aug 7, 2013 at 9:42 AM, iembry <iruckaE at mail2world.com> wrote:
> Hi Matthew, thank you.
>
> This is my function and I added the modified line that you suggested below:
> freadDataRatingDepotFiles <- function (file)
> {
> RDdatatmp <- fread(file, autostart=40)
> RDdatatmp <- RDdatatmp[,site:=funArg]
> }
>
> I used the function on the files and I received the error below:
>
> big = rbindlist(lapply(sitefiles,freadDataRatingDepotFiles))
> Error in eval(expr, envir, enclos) : object 'funArg' not found

The use of `funArg` wasn't a literal suggestion ... the "normal" rules
of programming apply here, which is to say that `funArg` (or whatever)
needs to be a defined variable before you can use it(!)

Likely Matthew used `funArg` as shorthand for "function argument", so
you could write your function like so (note that `:=` returns the
data.table it modified invisibly, so no need to reassign or call
`return()`):

freadDataRatingDepotFiles <- function(filename) {
  tmp <- fread(filename, autostart=40)
  tmp[, site := filename]
}

Now, split your code up into more manageable pieces so you can see and
verify what is going on:

R> dts <- lapply(sitefiles,freadDataRatingDepotFiles)
R> all(sapply(dts, is.data.table))

If the last statement doesn't evaluate to TRUE then you have a
problem. Assuming it is TRUE, now you simply:

R> big <- rbindlist(dts)

and continue ...

HTH,
-steve

-- 
Steve Lianoglou
Computational Biologist
Department of Bioinformatics and Computational Biology
Genentech


More information about the datatable-help mailing list