Can't render tidyverse 1.2 startup message in LaTex

I just upgraded to tidyverse v1.2.1 and now when I try to render an R Markdown file to pdf, I get the following error:

! Package inputenc Error: Unicode char √ (U+221A)
(inputenc)                not set up for use with LaTeX.

See the inputenc package documentation for explanation.
Type  H <return>  for immediate help.    

I know very little about LaTex, but it appears to not know how to handle the included in the new tidyverse startup message. Is this something I can deal with somewhere in my local LaTex set up?

As a workaround for now, I've just used suppressPackageStartupMessages(), but I would like to be able to render the startup message to pdf if possible.

I tend to pre-load packages in R md files with include = FALSE then use the code to load them again in the code chunks where they are first needed. That does hide the conflicts (which I always check) but the markdown output doesn't contain contain an entire page of messages.

2 Likes

That's a good tip, thanks @Max!

But I still would like the option to render the startup messages in a pdf, if possible. I'm sharing the document with total R beginners and want the code blocks I include in the document to look exactly like the console output. I'm able to render the to html like so:

So really just wondering if there is a way to print that same output in pdf format.

Standard LaTeX can't handle raw Unicode characters like √, but XeLaTeX can. Add latex_engine: xelatex to your YAML front matter:

output: 
  pdf_document: 
    latex_engine: xelatex
3 Likes

Aha! Works like a charm, @andrewheiss. Now, any ideas for how to get the output to wrap so it stays in the code block?

Ordinarily, you can set output width options in with knitr::opts_chunk(), like so:

```{r setup, include=FALSE}
knitr::opts_chunk$set(tidy.opts = list(width.cutoff = 60),  # For code
                      options(width = 60))  # For output
```

However, it doesn't look like the tidyverse message reads those output settings. I've filed an issue on GitHub: https://github.com/tidyverse/tidyverse/issues/92

2 Likes

Solution! Include options(cli.width = X) to modify the tidyverse message width. Here's a minimal working example:

---
title: "Testing"
output:
  pdf_document:
    latex_engine: xelatex
---

```{r setup}
knitr::opts_chunk$set(tidy.opts = list(width.cutoff = 60),  # For code
                      width = 60)  # For output

options(cli.width = 60)  # For tidyverse loading messages
```

```{r}
library(tidyverse)
```

This produces:

1 Like