r-lib / lifecycle

Manage the life cycle of your exported functions and arguments
https://lifecycle.r-lib.org
Other
94 stars 25 forks source link

Communicate vignette includes interactive output #175

Open hadley opened 10 months ago

hadley commented 10 months ago

Like:

#> This warning is displayed once every 8 hours.
#> Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
#> generated.

I tried explicitly disabling with:

options(rlang_interactive = FALSE)

But that didn't do anything. But I don't understand why is_interactive() would be true in the first place?

hadley commented 10 months ago

It looks like deprecate_warn0() gets called twice, the second time with call stack

     ▆
  1. └─rmarkdown::render("vignettes/test.Rmd")
  2.   └─knitr::knit(knit_input, knit_output, envir = envir, quiet = quiet)
  3.     └─knitr:::process_file(text, output)
  4.       ├─knitr:::handle_error(...)
  5.       │ └─base::withCallingHandlers(...)
  6.       ├─base::withCallingHandlers(...)
  7.       ├─knitr:::process_group(group)
  8.       └─knitr:::process_group.block(group)
  9.         └─knitr:::call_block(x)
 10.           └─knitr:::block_exec(params)
 11.             └─knitr:::eng_r(options)
 12.               ├─base::unlist(sew(res, options))
 13.               ├─knitr::sew(res, options)
 14.               └─knitr:::sew.list(res, options)
 15.                 └─base::lapply(x, sew, options, ...)
 16.                   ├─knitr (local) FUN(X[[i]], ...)
 17.                   ├─rlang (local) sew.rlang_warning(X[[i]], ...)
 18.                   ├─base::NextMethod()
 19.                   └─knitr:::sew.warning(X[[i]], ...)
 20.                     ├─knitr:::msg_wrap(...)
 21.                     │ └─base::grep("\n", message)
 22.                     │   └─base::is.factor(x)
 23.                     ├─base::sprintf("Warning%s: %s", call, conditionMessage(x))
 24.                     ├─base::conditionMessage(x)
 25.                     └─rlang:::conditionMessage.rlang_warning(x)
 26.                       └─rlang::cnd_message(c)
 27.                         └─rlang:::cnd_message_format(cnd, ...)
 28.                           └─rlang:::cnd_message_lines(cnd, ...)
 29.                             └─rlang::cnd_footer(cnd, ...)
 30.                               └─rlang:::exec_cnd_method("footer", cnd, ...)
 31.                                 └─lifecycle (local) method(cnd, ...)

Oh because footer() is generated lazily so it gets recomputed by knitr::sew() which is run in an interactive context.

This is super confusing but doesn't affect the rendered site, just the local previews.