当nrow> 100时出现data.table打印错误 [英] data.table print error when nrow>100

查看:60
本文介绍了当nrow> 100时出现data.table打印错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

打印数据表时会发生一个奇怪的错误,但仅当数据表的大小超过100时(以下示例)。
print()替换为 print.data.frame()时,错误消失。
因此,我的猜测是 print -> print.data.frame 继承仅在data.table的大小不超过100。

A strange error occurs when printing a data.table, but only when the data.table size is over 100 (example below). The error disappears when print() is replaced with print.data.frame(). Hence, my guess is that print-->print.data.frame inheritance is recognized only when data.table size is no more than 100.

有人可以直觉为什么会这样吗?
我的R版本是3.1.2。

Can someone give an intuition why this happens? My R version is 3.1.2.

library(data.table)

print(data.table(x=1:100), row.names=F) <-this command prints data.table

print(data.table(x=1:101), row.names=F) <- this command gives an error as below.

Error in `rownames<-`(`#tmp#`, value = rep.int("", nrow(x))) :
  length of 'dimnames' [1] not equal to array extent


推荐答案

您可能拥有 datatable.print.nrows 选项设置为默认值100。

You probably have your datatable.print.nrows option set to the default of 100.

getOption("datatable.print.nrows")
# [1] 100

您可以更改通过更改选项的值或使用 print.data.table()中的 nrows 来打印的行数。后者可能是最好的方法,因为它不会更改默认值。

You can change the number of printed rows by either changing the option's value or by using nrows in print.data.table(). The latter is probably the best way to go as it will not change the default value.

args(data.table:::print.data.table)
# function (x, topn = getOption("datatable.print.topn"), 
#     nrows = getOption("datatable.print.nrows"), row.names = TRUE, ...) 

这将起作用-

dt <- data.table(x = 1:101)
print(dt, nrows = nrow(dt), row.names = FALSE)

这篇关于当nrow&gt; 100时出现data.table打印错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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