@technocrat I think I figured it out. The above example:
---
title: "test"
output:
pdf_document: default
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
test <- "The temperature is 20 °C"
output <- gsub("\\x{00B0}", "\\\\textdegree", test)
```
`r output`
was breaking because \textdegreeC isn't valid latex. Changing "\\\\textdegree" to "\\\\textdegree " allowed for the correct encoding of the degree symbol. That was frustrating. Thanks for sticking with me.
Here's the working example that will compile:
---
title: "test"
output:
pdf_document: default
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
test <- "The temperature is 20 °C"
output <- gsub("\\x{00B0}", "\\\\textdegree ", test)
```
`r output`