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

Damian Betebenner dbetebenner at nciea.org
Wed Dec 15 01:58:26 CET 2010


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

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/datatable-help/attachments/20101214/f03d5b9b/attachment.htm>


More information about the datatable-help mailing list