[datatable-help] Question About data.table package

Matthew Dowle mdowle at mdowle.plus.com
Thu May 10 11:06:14 CEST 2012


Hi,

Thanks for your kind comments. Have confirmed Andrie's guess on SO and
added more info there.

Please either post here or to SO (whichever one you prefer), but not both.
Also please tag the question with the data.table tag (now done) which I'm
subscribed to, as well the r tag.

Thanks, Matthew


> Hello,
>
> I am using your data.table R package to apply a function to subsets of a
> large data set.  The performance of the package is absolutely fantastic,
> so I thank you for developing it.  I am running into one issue however,
> that I hope you can answer.
>
> I have posted the question on stackoverflow.com.  If you prefer to make
> the answer public, the link is:
> http://stackoverflow.com/questions/10527072/using-data-table-package-inside-my-own-package
>
> The question is as follows:
> I am trying to use the data.table package inside my own package. MWE is as
> follows:
> I create a function, test.fun, that simply creates a small data.table
> object, and then sums the "Val" column grouping by the "A" column. The
> code is
> test.fun<-function ()
> {
>     library(data.table)
>     testdata<-data.table(A=rep(seq(1,5), 5), Val=rnorm(25))
>     setkey(testdata, A)
>     res<-testdata[,{list(Ct=length(Val),Total=sum(Val),Avg=mean(Val))},"A"]
>     return(res)
> }
> When I create this function in a regular R session, and then run the
> function, it works as expected.
>> res<-test.fun()
> data.table 1.8.0  For help type: help("data.table")
>> res
>      A Ct      Total        Avg
> [1,] 1  5 -0.5326444 -0.1065289
> [2,] 2  5 -4.0832062 -0.8166412
> [3,] 3  5  0.9458251  0.1891650
> [4,] 4  5  2.0474791  0.4094958
> [5,] 5  5  2.3609443  0.4721889
> When I put this function into a package, install the package, load the
> package, and then run the function, I get an error message.
>> library(testpackage)
>> res<-test.fun()
> data.table 1.8.0  For help type: help("data.table")
> Error in `[.data.frame`(x, i, j) : object 'Val' not found
> Any help is very much appreciated.
> Thanks,
> Scott
> _______________________________________________
> datatable-help mailing list
> datatable-help at lists.r-forge.r-project.org
> https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/datatable-help




More information about the datatable-help mailing list