我正在使用最近推出的 fread
函数来自 data.table
读取数据文件。
当我将代码包装到 knitr (Rmd) 文档中时,我注意到一些奇怪的输出,即如下几行:
##
0%
即使
verbose
fread
的选项被设置为 FALSE。我用过 sink
隐藏此输出,但我想向包作者报告确切的问题。这是一个最小的例子,library(knitr)
test = "```{r}
require(data.table)
fread('1 2 3\n')
```"
knit2html(text=test, output="test.html")
browseURL("test.html")
什么是 0% 输出?
最佳答案
这是一个百分比进度计数器。对我来说,它用 \r
打印 0%、5%、10%、... 95%、100%(例如)最后使其出现在调用 fread
下方的一行中在提示下键入时。
但是当从函数、批处理和 knitr 调用时,这是不可取的。这现在已被删除。来自 v1.8.9 (rev 851) 的新闻:
- % progress console meter has been removed. The ouput was inconvenient in batch mode, log files and reports which don't handle
\r
. It was too difficult to detect wherefread
is being called from, plus, removing it speeds upfread
a little by saving code inside the C for loop (which is why it wasn't made optional instead). Use your operating system's system monitor to confirm fread is progressing. Thanks to Baptiste for highlighting :
Strange output from fread when called from knitr
只是为了完整性的快速提醒。从顶部
?fread
:This function is still under development. For example, dates are read as character (they can be converted afterwards using the excellent fasttime package or standard base functions) and embedded quotes ("\"" and """") have problems. There are other known issues that haven't been fixed and features not yet implemented. But, you may find it works in many cases. Please report problems to datatable-help or Stack Overflow's data.table tag.
Not for production use yet. Not because it's unstable in the sense that it crashes or is buggy (your testing will show whether it is stable in your cases or not) but because fread's arguments and behaviour is likely to change in future; i.e., we expect to make (hopefully minor) non-backwards-compatible changes. Why has it been released to CRAN then? Because a maintenance release was asked for by CRAN maintainers to comply with new stricter tests in R-devel, and a few Bioconductor packages depend on data.table and Bioconductor requires packages to pass R-devel checks. It was quicker to leave fread in and write these paragraphs, than take fread out.
关于r - 从 knitr 调用时 fread 的奇怪输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15370993/