yihui / knitr

A general-purpose tool for dynamic report generation in R
https://yihui.org/knitr/
2.37k stars 874 forks source link

unicode escape character (generated by **dplyr** warning?) generates error when rendering to .pdf #2234

Closed mikeroswell closed 10 months ago

mikeroswell commented 1 year ago

By filing an issue to this repo, I promise that

I understand that my issue may be closed if I don't fulfill my promises.

--

Error knitting to .pdf from .rmd seems to occur with warnings generated by dplyr, suggesting a problem with a unicode escape.

I was able to reproduce with this

---
title: "special_i"
author: "Michael Roswell"
date: "2023-02-24"
output: 
  pdf_document: 
    latex_engine: pdflatex
---
seems like the dplyr warning message creates problems with 

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(dplyr)
mtcars[1,"carb"] <- NA
mtcars %>% summarize_all(sqrt)

xfun::session_info('knitr') R version 4.2.2 (2022-10-31) Platform: aarch64-apple-darwin20 (64-bit) Running under: macOS Ventura 13.2.1, RStudio 2022.12.0.353

Locale: en_US.UTF-8 / en_US.UTF-8 / en_US.UTF-8 / C / en_US.UTF-8 / en_US.UTF-8

Package version: evaluate_0.20 graphics_4.2.2 grDevices_4.2.2 highr_0.10 knitr_1.42
methods_4.2.2 stats_4.2.2 tools_4.2.2 utils_4.2.2 xfun_0.37
yaml_2.3.7



https://stackoverflow.com/q/75504968/8400969
mikeroswell commented 1 year ago

c.f. #2231

cderv commented 1 year ago

For more context, this is the emitted warning that shows in knitted output with dplyr image

It does not seems like the output link is correct for support with knitr. I think this is an issue with dplyr or maybe cli which should be what is used there.

Usually the ANSI code formatting for cli use to get nice output in console should be deactivating when knitting.

See also with html_document()

image

BTW regarding #2231, this is a matter of latex_engine, and xelatex should be used when unicode https://bookdown.org/yihui/rmarkdown-cookbook/latex-unicode.html

It does not solve issue here, because I think there is something that shouldn't be printed anyway.

cderv commented 1 year ago

The message comes from lifecycle package https://github.com/r-lib/lifecycle/blob/80a1e521f995671d062a338856110198b3cdd5e3/R/deprecate.R#L221-L225 with the use of {.url {url}} formatting in cli

This is ultimately an issue within cli

> xfun::raw_string(
+     knitr::knit(text = c("```{r}", 'url <- "https://github.com/yihui/knitr/issues"', 'cli::format_inline("Please report the issue at {.url {url}}.")', '```'))
+ )

```r
url <- "https://github.com/yihui/knitr/issues"
cli::format_inline("Please report the issue at {.url {url}}.")
## [1] "Please report the issue at <\033]8;;https://github.com/yihui/knitr/issues\ahttps://github.com/yihui/knitr/issues\033]8;;\a>."

What is expected is all the ANSI formatting to be removed 
````r
> xfun::raw_string(
+     knitr::knit(text = c("```{r}", 'cli::format_inline("A message for {.emph later}, thanks {.fn format_inline}.")', '```'))
+ )

```r
cli::format_inline("A message for {.emph later}, thanks {.fn format_inline}.")
## [1] "A message for later, thanks `format_inline()`."
mikeroswell commented 1 year ago

Looks like it's on their radar: https://github.com/r-lib/cli/issues/581#issue-1576635242

cderv commented 1 year ago

yes thanks, I was writing a message there. Didn't know you where also digging into that.

mikeroswell commented 1 year ago

Thanks, your message was more helpful! Since I had complained in the first place, I figured it might be my job to close the loop.

gaborcsardi commented 1 year ago

This should be fixed in dev cli: https://github.com/r-lib/cli/issues/581 Can you please confirm?

cderv commented 1 year ago

It works for me now with your example @mikeroswell and dev cli

github-actions[bot] commented 4 months ago

This old thread has been automatically locked. If you think you have found something related to this, please open a new issue by following the issue guide (https://yihui.org/issue/), and link to this old issue if necessary.