r - 从 knitr 调用时 fread 的奇怪输出

标签 r data.table knitr

我正在使用最近推出的 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 where fread is being called from, plus, removing it speeds up fread 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/

相关文章:

r - 防止 `knitr` 弹出绘图窗口

r - 如何在所有其他代码块之后强制 Knitr 评估\Sexpr

java - rJava::.jnew ("edu.stanford.nlp.pipeline.StanfordCoreNLP"中的错误,基本名称(路径))

R:错误应用于类 "c(' 整数', 'numeric' ) 的对象”

R 中带有神经网络包的 ReLU 激活函数

r绑定(bind) data.table 列表的列表

r - 根据 ID 将值复制到其他 NA 单元

r - 在 RStudio 中执行 "cannot open the connection"时出现错误 "knit HTML"

r - 在 Web 访问 session 中查找请求的页面对的时间差

r - 如何避免用data.table打印行号?