[datatable-help] Using data.table within another package/scoping

Matthew Dowle mdowle at mdowle.plus.com
Wed Dec 15 02:14:19 CET 2010


Hi,

> Calls: dataTableTest1 ... eval -> eval -> [ -> [.data.table ->
[.data.frame -> mean

Looks like [.data.frame is being dispatched. To use data.table in your
package you'll need the latest version on R-Forge, put data.table in
Imports rather than Depends, and your package will need a namespace.
Hope that works.

Matthew

On Tue, 2010-12-14 at 18:58 -0600, Damian Betebenner wrote:
> All,
> 
>  
> 
> I have been trying to integrate data.table into a package I produce
> and keep having problems with an “object not found” issue.
> 
> When I source the function, it works, but when it is put into a
> package it doesn’t work.
> 
>  
> 
> Here’s a simple example giving the same results:
> 
>  
> 
> dataTableTest1 <- function(n) {
> 
>       my.dt <- data.table(rep(1:n, each=5), rnorm(5*n))
> 
>       names(my.dt) <- c("ID", "SCORE") 
> 
>       my.dt
> 
>       eval(parse(text="my.dt[,mean(SCORE), by=ID]"))
> 
> }
> 
>  
> 
> After embedding this into a package, in the man page for the function
> I run the test dataTableTest1(5):
> 
> Below are the results of the dataTableTest-Ex.Rout
> 
>  
> 
> R version 2.11.1 (2010-05-31)
> 
> Copyright (C) 2010 The R Foundation for Statistical Computing
> 
> ISBN 3-900051-07-0
> 
>  
> 
> R is free software and comes with ABSOLUTELY NO WARRANTY.
> 
> You are welcome to redistribute it under certain conditions.
> 
> Type 'license()' or 'licence()' for distribution details.
> 
>  
> 
>   Natural language support but running in an English locale
> 
>  
> 
> R is a collaborative project with many contributors.
> 
> Type 'contributors()' for more information and
> 
> 'citation()' on how to cite R or R packages in publications.
> 
>  
> 
> Type 'demo()' for some demos, 'help()' for on-line help, or
> 
> 'help.start()' for an HTML browser interface to help.
> 
> Type 'q()' to quit R.
> 
>  
> 
> > pkgname <- "dataTableTest"
> 
> > source(file.path(R.home("share"), "R", "examples-header.R"))
> 
> > options(warn = 1)
> 
> > library('dataTableTest')
> 
> Loading required package: data.table
> 
> > 
> 
> > assign(".oldSearch", search(), pos = 'CheckExEnv')
> 
> > cleanEx()
> 
> > nameEx("dataTableTest1")
> 
> > ### * dataTableTest1
> 
> > 
> 
> > flush(stderr()); flush(stdout())
> 
> > 
> 
> > ### Name: dataTableTest1
> 
> > ### Title: data.table test function
> 
> > ### Aliases: dataTableTest1
> 
> > ### Keywords: misc models
> 
> > 
> 
> > ### ** Examples
> 
> > 
> 
> > dataTableTest1(5)
> 
> Error in mean(SCORE) : object 'SCORE' not found
> 
> Calls: dataTableTest1 ... eval -> eval -> [ -> [.data.table ->
> [.data.frame -> mean
> 
> Execution halted
> 
>  
> 
>  
> 
>  
> 
> Any help understanding why SCORE is found when the function is sourced
> but is not found when the function is embedded in the package would be
> greatly appreciated.
> 
>  
> 
> Best regards,
> 
>  
> 
>  
> 
> Damian
> 
>  
> 
> 
> _______________________________________________
> 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