> ## Content Index
> Fetch the complete content index at: https://www.saraburke.net/llms.txt
> Use this file to discover other available public pages before exploring further.

# R: Set Font Based on Output Device
- URL: https://www.saraburke.net/r-set-font-based-on-output-device/
- Published: 2018-01-16T05:00:00.000Z
- Updated: 2022-12-29T06:48:26.000Z
- Author: Sara Burke

Ever had a troublesome font in R that doesn’t want to render to `ggplot` in RStudio, but will render just fine in `knitr`? Do you use `extrafont` but sometimes it just doesn’t work? Trying to look like Tufte’s [*Visual Display of Quantitative Information*](https://www.amazon.com/Visual-Display-Quantitative-Information/dp/1930824130/ref=as%5Fli%5Fss%5Ftl?ie=UTF8&linkCode=ll1&tag=blatchdotnet-20&linkId=cb1e231d5e4bfed6308395798010e69e&ref=saraburke.net) but ETBembo is being uncooperative? Try setting your font (globally) to this.

```r
myfont <- ifelse(is.null(knitr::opts_knit$get("rmarkdown.pandoc.to")), "serif", "ETBembo")

```

This sets `myfont` to `serif` if the code is being rendered in anything but `knitr`. If it *is* being rendered by `knitr`, say, by pressing the “Knit” button in RStudio, then it sets it to ETBembo.

I found it on [StackOverflow](https://stackoverflow.com/questions/35144130/in-knitr-how-can-i-test-for-if-the-output-will-be-pdf-or-word?ref=saraburke.net#35149103).