data.table throws "object not found" error
15,411
Great reproducible question! Here's what I get. You didn't post your output as well, so perhaps you don't get the same output at me. I've split the output and placed HERE where the problem might be.
$ R
R version 3.1.0 (2014-04-10) -- "Spring Dance"
Copyright (C) 2014 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
> library(devtools)
> setwd(tempdir())
> # make dummy package called foo
> create("foo")
Creating package foo in .
No DESCRIPTION found. Creating with values:
Package: foo
Title:
Description:
Version: 0.1
Authors@R: # getOptions('devtools.desc.author')
Depends: R (>= 3.1.0)
License: # getOptions('devtools.desc.license')
LazyData: true
> setwd("foo")
>
> # add data.table as a package dependency
> a <- readLines("DESCRIPTION")
> depends.idx <- grepl("Depends", a)
> a[depends.idx] <- paste0(a[depends.idx], ", data.table")
> writeLines(a, "DESCRIPTION")
>
> # create a dummy function
> writeLines("myfunction <- function() {a <- data.table(b=1); return(a[,b])}",
+ "R/foo.R")
>
> # check and throw error
> check()
Loading required package: roxygen2
Updating foo documentation
Loading foo
HERE :
Invalid DESCRIPTION:
Authors@R field gives no person with author role.
Authors@R field gives no person with maintainer role and email address.
See the information on DESCRIPTION files in section 'Creating R packages' of the 'Writing R Extensions' manual.
Loading required package: data.table
data.table 1.9.2 For help type: help("data.table")
Attaching package: ‘data.table’
The following object is masked from ‘package:bit’:
setattr
Updating collate directive in /tmp/Rtmp0h3yz9/foo/DESCRIPTION
Updating namespace directives
Writing foo.Rd
'/usr/lib/R/bin/R' --vanilla CMD build '/tmp/Rtmp0h3yz9/foo' --no-manual --no-resave-data
* checking for file '/tmp/Rtmp0h3yz9/foo/DESCRIPTION' ... OK
* preparing 'foo':
HERE :
* checking DESCRIPTION meta-information ... ERROR
Authors@R field gives no person with author role.
Authors@R field gives no person with maintainer role and email address.
See the information on DESCRIPTION files in section 'Creating R
packages' of the 'Writing R Extensions' manual.
Error: Command failed (1)
> library(foo)
> myfunction()
Error in `[.data.frame`(x, i, j) : object 'b' not found
>
Related videos on Youtube
Author by
Abe
Updated on September 16, 2022Comments
-
Abe over 1 year
I have a data.table:
library(data.table) mydt <- data.table(index = 1:10)
I am getting this to work when I try it in the global environment, but not when I am in the debugger or when I use it in a package test.
The problem is that I can not subset it in the standard ways.
Browse[2]> mydt[,index] Error in `[.data.frame`(x, i, j) : object 'index' not found Browse[2]> mydt[,list(index)] Error in `[.data.frame`(x, i, j) : object 'index' not found
Here is a reproducible example, in which I create a package and then get the error when I evaluate the function called
myfunction
:library(devtools) setwd(tempdir()) # make dummy package called foo create("foo") setwd("foo") # add data.table as a package dependency a <- readLines("DESCRIPTION") depends.idx <- grepl("Depends", a) a[depends.idx] <- paste0(a[depends.idx], ", data.table") writeLines(a, "DESCRIPTION") # create a dummy function writeLines("myfunction <- function() {a <- data.table(b=1); return(a[,b])}", "R/foo.R") # check and throw error check() library(foo) myfunction()
Here is the session info:
Browse[2]> sessionInfo() R version 3.0.2 (2013-09-25) Platform: x86_64-pc-linux-gnu (64-bit) locale: [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C LC_TIME=C LC_COLLATE=C LC_MONETARY=C [6] LC_MESSAGES=C LC_PAPER=C LC_NAME=C LC_ADDRESS=C LC_TELEPHONE=C [11] LC_MEASUREMENT=C LC_IDENTIFICATION=C attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] PEcAn.data.atmosphere_1.3.3 data.table_1.9.2 RPostgreSQL_0.4 PEcAn.settings_1.3.3 [5] lubridate_1.3.3 PEcAn.DB_1.3.3 DBI_0.2-7 PEcAn.utils_1.3.3 [9] udunits2_0.6 ncdf4_1.12 randtoolbox_1.14 rngWELL_0.10-2 [13] ggplot2_1.0.0 XML_3.98-1.1 plyr_1.8.1 abind_1.4-0 [17] testthat_0.8.1 devtools_1.5.0.99 loaded via a namespace (and not attached): [1] MASS_7.3-29 RCurl_1.95-4.1 Rcpp_0.11.2 colorspace_1.2-4 digest_0.6.4 evaluate_0.5.5 grid_3.0.2 [8] gtable_0.1.2 httr_0.3 memoise_0.2.1 munsell_0.4.2 parallel_3.0.2 proto_0.3-10 reshape2_1.4 [15] roxygen2_4.0.1 scales_0.2.4 stringr_0.6.2 tools_3.0.2 whisker_0.3-2
-
Admin almost 10 yearsThere is no
index
object in your workspace. Create it first. -
Abe almost 10 years@Pascal
index
is a column name for the data.table. If you are not familiar with the data.table package, one feature is that it allows indexing without putting quotes around the column names. -
Admin almost 10 yearsI understand. But it is a question of workspace and namespace I guess.
-
Abe almost 10 years@Pascal could you elaborate? How might I get the object to behave as expected?
-
mnel almost 10 yearsFrom where are you calling
browser
? Can you post a reproducible example. -
Abe almost 10 years@mnel I have provided a reproducible example, it requires putting this all into a dummy package. It doesn't enter the browser; but I would do so in the example by using
debugonce(foo)
-
MrFlick almost 10 yearsIs the
a[6]
value the "Depends" line? -
Abe almost 10 years@MrFlick yes ... but now I realize my example is wrong ... I'll try and fix it
-
Abe almost 10 years@MrFlick The reproducible example throws the error now; I've also clarified the indexing
-
Admin almost 10 yearsDid you notice this lines during checking? * checking dependencies in R code ... NOTE Package in Depends field not imported from: 'data.table' These packages need to be imported from (in the NAMESPACE file) for when this namespace is loaded but not attached.
-
Matt Dowle almost 10 yearsHave you followed stackoverflow.com/a/10529888/403310 ?
-
Abe almost 10 years@MattDowle Isn't that demonstrated in the reproducible example that I posted? It says to put
data.table
in the Depends section of the DESCRIPTION file, correct? -
Matt Dowle almost 10 years@Abe Sorry my bad. Yes it reproduces (great question!) and I'll add an answer.
-
eddi almost 10 yearsSeems like
data.table:::cedta
expects to find a ".Depends" object in the package that would list the dependencies, in particulardata.table
and doesn't - I don't know if this is smth that has changed in R. Perhaps you can try the import method instead? -
eddi almost 10 yearsbtw a very simple workaround is to add a global
.datatable.aware=TRUE
to your package - e.g.writeLines(".datatable.aware=TRUE; myfunction...
-
Abe almost 10 years@eddi it works ... thanks! why not post as an answer?
-
Arun almost 10 years
-
Abe almost 10 years@arun yes, appears to be the same
-
krlmlr almost 9 yearsCan't replicate this issue anymore: github.com/hadley/devtools/issues/192#issuecomment-105451177
-
-
Abe almost 10 yearsseems to be an old devtools bug github.com/hadley/devtools/issues/192