【问题标题】:Is it possible to disable `callr` for RMarkdown?是否可以为 RMarkdown 禁用`callr`?
【发布时间】:2019-12-15 03:34:49
【问题描述】:

在尝试为 {disk.frame} 构建小插图时,我不断收到错误消息。我认为这是由于使用 NSE 的 {callr} 的错误行为。

是否可以不将 {callr} 与 RMarkdown 一起使用?我认为 {callr} 在后台创建了一个新的 R 会话,但如果我只是使用同一个会话来构建 Markdown,那么我应该没问题。但我在 Rmarkdown 文档中找不到可以禁用 {callr} 的位置。

--- re-building 'intro-disk-frame.Rmd' using rmarkdown
Quitting from lines 230-235 (intro-disk-frame.Rmd) 
Error: processing vignette 'intro-disk-frame.Rmd' failed with diagnostics:
no applicable method for 'filter_' applied to an object of class "NULL"
--- failed re-building 'intro-disk-frame.Rmd'

SUMMARY: processing the following file failed:
  'intro-disk-frame.Rmd'

Error : Vignette re-building failed.

Error: <callr_status_error: callr subprocess failed: Vignette re-building failed.>
-->
<callr_remote_error: Vignette re-building failed.>
 in process 17276 

See `.Last.error.trace` for a stack trace.
Warning message:
In df_setup_vignette(excl = c("08-more-epic.Rmd", "06-vs-dask-juliadb.Rmd",  :
  NAs introduced by coercion

更新

这是你可以尝试的代码

---
title: "Test"
output: rmarkdown::html_vignette
---

``` {r setup, include = FALSE}
remotes::install_github("xiaodaigh/disk.frame", ref="development")
suppressPackageStartupMessages(library(disk.frame))
library(fst)
library(magrittr)
library(nycflights13)
library(dplyr)
library(data.table)

# you need to run this for multi-worker support
# limit to 2 cores if not running interactively; most likely on CRAN
# set-up disk.frame to use multiple workers
if(interactive()) {
  setup_disk.frame()
  # highly recommended, however it is pun into interactive() for CRAN because
  # change user options are not allowed on CRAN
  options(future.globals.maxSize = Inf)  
} else {
  setup_disk.frame(2)
}


knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)
```

```{r asdiskframe, cache=TRUE}
library(nycflights13)
library(dplyr)
library(disk.frame)
library(data.table)

# convert the flights data to a disk.frame and store the disk.frame in the folder
# "tmp_flights" and overwrite any content if needed
flights.df <- as.disk.frame(
  flights, 
  outdir = file.path(tempdir(), "tmp_flights.df"),
  overwrite = TRUE)

flights.df
```

```{r, dependson='asdiskframe'}
library(disk.frame)
flights.df %>%
  group_by(carrier) %>% # notice that hard_group_by needs to be set
  summarize(count = n(), mean_dep_delay = mean(dep_delay, na.rm=T)) %>%  # mean follows normal R rules
  collect %>% 
  arrange(carrier)
```

【问题讨论】:

  • 您可以 a) 以eval=FALSE 模式显示代码,然后 b) 显示(预先计算的、固定的)输出。有时这些设置很脆弱,可能需要采取更具防御性的方法。
  • 看来您的问题不是callr 失败,而是它返回了一个错误......它表现正确。 callr 正在返回一个错误,因为您的文档失败(请参阅有关 "no applicable method for 'filter_' ... NULL" 的错误,可能是因为您没有在文档中正确实例化数据) . (顺便说一句:如果是 dplyr::filter_,则已弃用。)
  • r2evans,但是当我在交互模式下运行它时它会运行。无论如何,disk.frame 加载 dplyr 所以它不应该丢失
  • “它在交互模式下运行......” 而不是在呈现表明您没有在文档中定义它需要的数据时。如果您开始一个新的工作区(在ls(all.names=TRUE) 中找不到任何内容)并逐个运行文档,它仍然可以正常工作吗? (重要的是从一个空的环境开始并仅运行 rmarkdown 文档中存在的代码。在文档中无意中使用当前会话中的数据是很常见的事情,从而使它们无法重现。)
  • 我编辑了关于“无适用方法”的评论。问题是某些对象未正确定义,因此您实际上是在调用x &lt;- NULL; filter_(x, ...)

标签: r r-markdown callr


【解决方案1】:

基于此处https://community.rstudio.com/t/error-with-callr-not-doing-nse-the-way-disk-frame-does-causing-issue-with-knitting-in-rmarkdown/47401的讨论

可以直接在文件上使用rmarkdown::render() 来规避问题。

【讨论】:

    猜你喜欢
    • 2023-03-18
    • 1970-01-01
    • 1970-01-01
    • 2021-04-17
    • 2014-10-08
    • 2014-11-20
    • 1970-01-01
    • 1970-01-01
    • 2021-03-24
    相关资源
    最近更新 更多