data.table throws“object not found”。错误 [英] data.table throws "object not found" error

查看:1125
本文介绍了data.table throws“object not found”。错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个data.table:

  library(data.table)
mydt< - data。表(索引= 1:10)

当我在全局环境,但不是当我在调试器或当我在包测试中使用它。



问题是,我不能以标准方式子集。

 浏览[2]> mydt [,index] 
错误在`[.data.frame`(x,i,j):object'index'not found
Browse [2] mydt [,list(index)]
错误在`[.data.frame`(x,i,j):object'index'not found

这是一个可重现的例子,其中我创建一个包,然后得到错误时,我评估的函数 myfunction

  library(devtools)
setwd(tempdir())
#make dummy package foo
create(foo)
setwd(foo)

#作为包依赖关系添加data.table
a< - readLines(DESCRIPTION)
depends.idx < - grepl(Depends,a)
a [depends.idx]< - paste0(a [depends.idx],,data.table)
writeLines(a,DESCRIPTION)

#创建一个虚拟函数
writeLines(myfunction< - function(){a< - data.table(b = 1); return (a [,b])},
R / foo.R)

检查并抛出错误
check()

myfunction()

这里是会话信息:

 浏览[2]> sessionInfo()
R版本3.0.2(2013-09-25)
平台:x86_64-pc-linux-gnu(64位)

语言环境:
[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

附加的基本软件包:
[1] stats graphics grDevices utils数据集方法base

其他附加软件包:
[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

通过命名空间加载(未附加):
[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


解决方案

伟大的可重复的问题!这是我得到的。你没有发布你的输出,所以也许你没有得到相同的输出在我。我已拆分输出,并将此处放置在可能出现问题的位置。

  $ R 
R版本3.1.0(2014-04-10) - 春舞
版权所有(C)2014 R统计计算基金会
平台:x86_64-pc-linux-gnu -bit)

> library(devtools)
> setwd(tempdir())
> #make dummy package foo
> create(foo)
在中创建包foo。
未找到DESCRIPTION。用值创建:

软件包:foo
标题:
描述:
版本:0.1
作者@ R:#getOptions('devtools.desc。
取决于:R(> = 3.1.0)
许可证:#getOptions('devtools.desc.license')
LazyData:true
> setwd(foo)
>
> #add data.table as a package dependency
> a< - readLines(DESCRIPTION)
> depends.idx< - grepl(Depends,a)
> a [depend.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()
加载所需软件包:roxygen2
更新foo文档
加载foo


$ b b

HERE

 无效DESCRIPTION:
作者角色的人。
作者@ R字段不给任何人提供维护者角色和电子邮件地址。

请参阅Writing R Extensions手册中的Creating R packages一节中有关DESCRIPTION文件的信息。

正在加载所需软件包:data.table
data.table 1.9.2对于帮助类型:help(data.table)

附加软件包:'data .table'

以下对象从'package:bit'中被屏蔽:

setattr

更新/ tmp / Rtmp0h3yz9 / foo中的collat​​e指令/ DESCRIPTION
更新命名空间指令
编写foo.Rd
'/ usr / lib / R / bin / R'--vanilla CMD build'/ tmp / Rtmp0h3yz9 / foo'手动--no-resave-data

*检查文件'/ tmp / Rtmp0h3yz9 / foo / DESCRIPTION'... OK
* prepare'foo':



此处

  * checking DESCRIPTION元信息...错误
作者@ R字段不授予任何人作者角色。
作者@ R字段不给任何人提供维护者角色和电子邮件地址。

请参阅Writing R Extensions手册中的Creating R
packages一节中有关DESCRIPTION文件的信息。

错误:命令失败(1)
> library(foo)
> myfunction()
在`[.data.frame`(x,i,j)中出现错误:object'b'not found
>


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      

解决方案

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
> 

这篇关于data.table throws“object not found”。错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆