[datatable-help] Question About data.table package
Scott Murray
SCOTT.Murray at baruch.cuny.edu
Thu May 10 05:39:54 CEST 2012
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/datatable-help/attachments/20120510/b9542b0c/attachment.html>
More information about the datatable-help
mailing list