Git Product home page Git Product logo

Comments (36)

hrbrmstr avatar hrbrmstr commented on September 12, 2024 5

gosh i hate fonts in Linux, BSD and R and Python

from hrbrthemes.

RoyalTS avatar RoyalTS commented on September 12, 2024 5

The extrafont setup, in particular running font_import() did the trick. Thanks a bunch!

from hrbrthemes.

RoyalTS avatar RoyalTS commented on September 12, 2024 4

Hmm, the following minimal reproducible example does not work for me:

---
title: "test"
output: pdf_document
---

```{r setup, include=FALSE}
library(dplyr)
library(ggplot2)
library(hrbrthemes)
extrafont::loadfonts(quiet=TRUE)
```

```{r}
iris %>%
  ggplot(aes(Sepal.Length, Sepal.Width)) + geom_point() + theme_ipsum()
```

It throws

Error in grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y,  : 
  invalid font type
Calls: <Anonymous> ... drawDetails -> drawDetails.text -> grid.Call.graphics
In addition: There were 50 or more warnings (use warnings() to see the first 50)
Execution halted

from hrbrthemes.

ajaquith avatar ajaquith commented on September 12, 2024 3

Hey Bob, just wanted to let you know that the addition of the extrafont::loadfonts(quiet=TRUE) to .Rmd code chunks solved a problem I was having. Praise be to the search gods. Thanks!

from hrbrthemes.

hrbrmstr avatar hrbrmstr commented on September 12, 2024 2

add extrafont::loadfonts() after library(tidyverse) so the PDF NULL graphics device can see the fonts.

image

No warnings now.

from hrbrthemes.

hrbrmstr avatar hrbrmstr commented on September 12, 2024 2

Ah, fonts and R/Python.

You need TTF versions of the fonts for them to work across devices consistently in R.

Said fonts need to be installed at the system-level.

You also need to ensure you've added the fonts to R using the procedures described in extrafont.

This pkg tries to take care of the loading bit on startup now (recent dev update).

The hack @bhaskarvk mentioned is due to knitr using a null PDF device behind the scenes, a process that tosses warnings since the context it executes in doesn't have the fonts loaded.

^^^ is one big reason ggplot2 doesn't do anything fancy with fonts in the pkg or examples since anything outside the basic fonts isn't going to work without some pain.

from hrbrthemes.

hrbrmstr avatar hrbrmstr commented on September 12, 2024 1

ah. lemme poke at that

from hrbrthemes.

bhaskarvk avatar bhaskarvk commented on September 12, 2024 1

Nope that didn't do it.
But adding the following does get rid of the warning.

knitr::opts_chunk$set(dev = 'svg')
options(device = function(file, width, height) {
  svg(tempfile(), width = width, height = height)
})

Ditto for png.

from hrbrthemes.

hrbrmstr avatar hrbrmstr commented on September 12, 2024 1

from hrbrthemes.

bhaskarvk avatar bhaskarvk commented on September 12, 2024 1

@RoyalTS For the warning part, I had to

options(device = function(file, width, height) {
  png(tempfile(), width = width, height = height)
})

As described in yihui/knitr#729 (comment)

I tried with a bunch of formats like png/svg/jpg etc. and did not get any warnings.

from hrbrthemes.

bhaskarvk avatar bhaskarvk commented on September 12, 2024

Could be related to yihui/knitr#729

from hrbrthemes.

hrbrmstr avatar hrbrmstr commented on September 12, 2024
---
title: "hrbrthemes testbed"
output: html_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

```{r message=FALSE}
library(hrbrthemes)
library(tidyverse)
```

### Arial Narrow

```{r}
ggplot(mtcars, aes(wt, mpg)) +
  geom_point() +
  labs(title="Arial Narrow", subtitle="This is a subtitle") +
  theme_ipsum()
```

### Roboto Condensed

```{r}
ggplot(mtcars, aes(wt, mpg)) +
  geom_point() +
  labs(title="Roboto Condensed", subtitle="This is a subtitle") +
  theme_ipsum_rc()
```

Generated no errors, messages or warnings on macOS Sierra & R 3.3.2

image

from hrbrthemes.

bhaskarvk avatar bhaskarvk commented on September 12, 2024

OK with html_output I don't get the warning too. But If I change the output to flexdashboard::flex_dashboard, then I do get the warnings.

from hrbrthemes.

bhaskarvk avatar bhaskarvk commented on September 12, 2024

It works if I use the work around mentioned in yihui/knitr#729 (comment).
So not an hrbrmstr issue then.
I'll let you poke at it a bit but feel free to close it.

from hrbrthemes.

hrbrmstr avatar hrbrmstr commented on September 12, 2024
---
title: "hrbrthemes flexdashboard"
output: 
  flexdashboard::flex_dashboard:
    orientation: columns
    vertical_layout: fill
---

```{r setup, include=FALSE}
library(flexdashboard)
library(hrbrthemes)
library(tidyverse)
```

Column {data-width=650}
-----------------------------------------------------------------------

### Roboto Condensed

```{r}
ggplot(mtcars, aes(wt, mpg)) +
  geom_point() +
  labs(title="Roboto Condensed", subtitle="This is a subtitle") +
  theme_ipsum_rc()
```

Column {data-width=350}
-----------------------------------------------------------------------

### Arial Narrow

```{r}
ggplot(mtcars, aes(wt, mpg)) +
  geom_point() +
  labs(title="Arial Narrow", subtitle="This is a subtitle") +
  theme_ipsum()
```

### More Roboto Condensed

```{r}
ggplot(mtcars, aes(wt, mpg)) +
  geom_point() +
  labs(title="Roboto Condensed", subtitle="This is a subtitle") +
  theme_ipsum_rc()
```

image

from hrbrthemes.

hrbrmstr avatar hrbrmstr commented on September 12, 2024

Just used straight flexdasboard base layout. No hacks.

from hrbrthemes.

bhaskarvk avatar bhaskarvk commented on September 12, 2024

It works, but check your 'R Markdown' tab,
For me it shows


Output created: t2.html
There were 50 or more warnings (use warnings() to see the first 50)

from hrbrthemes.

hrbrmstr avatar hrbrmstr commented on September 12, 2024

oh. aye! same here. one sec. i have a theory

from hrbrthemes.

hrbrmstr avatar hrbrmstr commented on September 12, 2024

huh. wondering why it worked here? (no warnings here after i did that extrafont dance)

from hrbrthemes.

hrbrmstr avatar hrbrmstr commented on September 12, 2024

what abt library(svglite); knitr::opts_chunk$set(dev = 'svglite') and no knitr hack but include the extrafont thing?

from hrbrthemes.

bhaskarvk avatar bhaskarvk commented on September 12, 2024

Nope! What's more svglite doesn't render the font correctly (w/ or w/o knitr hack).

Imgur

from hrbrthemes.

bhaskarvk avatar bhaskarvk commented on September 12, 2024

I'm fine relying on the knitr hack FWIW. But you'll probably need to document the workaround.

from hrbrthemes.

hrbrmstr avatar hrbrmstr commented on September 12, 2024

Wow. The inconsistencies between operating systems and even same OS but different devices is kind of disconcerting (my svglite versions work fine as do the other "hacks"). Def do need to doc this tho. Mebbe a GSOC to "fix font stuff in R" is in order (prbly a multi-GSOC effort).

from hrbrthemes.

RoyalTS avatar RoyalTS commented on September 12, 2024

What's the fix for this if I want the output to be pdf_output?

from hrbrthemes.

hrbrmstr avatar hrbrmstr commented on September 12, 2024

from hrbrthemes.

RoyalTS avatar RoyalTS commented on September 12, 2024

Oh, sorry, I meant setting output: pdf_document instead of output: html_document in the Rmd document, which I do all the time.

from hrbrthemes.

RoyalTS avatar RoyalTS commented on September 12, 2024
> sessionInfo()
R version 3.3.2 (2016-10-31)
Platform: x86_64-apple-darwin13.4.0 (64-bit)
Running under: macOS Sierra 10.12.3

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] hrbrthemes_0.1.0 ggplot2_2.2.1    dplyr_0.5.0     

loaded via a namespace (and not attached):
 [1] Rcpp_0.12.9.1    Rttf2pt1_1.3.4   knitr_1.15.1     magrittr_1.5     munsell_0.4.3    colorspace_1.3-2
 [7] R6_2.2.0         stringr_1.2.0    plyr_1.8.4       tools_3.3.2      hunspell_2.3     grid_3.3.2      
[13] gtable_0.2.0     DBI_0.5-14       extrafontdb_1.0  htmltools_0.3.5  yaml_2.1.13      lazyeval_0.2.0  
[19] assertthat_0.1   digest_0.6.12    rprojroot_1.2    tibble_1.2       purrr_0.2.2      evaluate_0.10   
[25] rmarkdown_1.3    labeling_0.3     stringi_1.1.2    scales_0.4.1     backports_1.0.5  extrafont_0.17  

from hrbrthemes.

hrbrmstr avatar hrbrmstr commented on September 12, 2024

from hrbrthemes.

RoyalTS avatar RoyalTS commented on September 12, 2024

Installed as in "it shows up in Font Book"? Yes.

Are you compiling using pdfLaTeX or XeLaTeX?

from hrbrthemes.

hrbrmstr avatar hrbrmstr commented on September 12, 2024

from hrbrthemes.

RoyalTS avatar RoyalTS commented on September 12, 2024

Ah, there might be an uncontrolled difference here: What device are you outputting to?

I can get my test document to work if I set knitr::opts_chunk$set(dev = 'png'), but not if I set knitr::opts_chunk$set(dev = 'pdf') and @bhaskarvk's solution seems to be one that's geared towards png, right?

from hrbrthemes.

RoyalTS avatar RoyalTS commented on September 12, 2024

Wait a second: I need not only Arial Narrow to be installed, I also need that to be the PostScript and not the TrueType version of the font?

from hrbrthemes.

tjmahr avatar tjmahr commented on September 12, 2024

I had the same error using these themes with LaTeX via RMarkdown on Windows. Doing a one-time font_import() like this comment suggests fixed it.

Other Windows people with pdf woes, try extrafont::font_import() first.

from hrbrthemes.

hrbrmstr avatar hrbrmstr commented on September 12, 2024

I now remember that this is one reason import_roboto_condensed() exists in-package.

from hrbrthemes.

yonicd avatar yonicd commented on September 12, 2024

i am getting this issue on the macOS with

---
output: 
  github_document:
    dev: svg

always_allow_html: yes
---

from hrbrthemes.

IndrajeetPatil avatar IndrajeetPatil commented on September 12, 2024

I am getting the same error on a Windows machine.

Here is my yaml config for .Rmd file.

---
  output: github_document
---

{r, echo = FALSE}
knitr::opts_chunk$set(
  collapse = TRUE,
  dpi = 300,
  out.width = "100%",
  comment = "#>",
  fig.path = "man/figures/README-"
)

And here is session info:

devtools::session_info()
#> Session info -------------------------------------------------------------
#>  setting  value                       
#>  version  R version 3.5.1 (2018-07-02)
#>  system   x86_64, mingw32             
#>  ui       RTerm                       
#>  language (EN)                        
#>  collate  English_United States.1252  
#>  tz       America/New_York            
#>  date     2018-08-29
#> Packages -----------------------------------------------------------------
#>  package   * version date       source        
#>  backports   1.1.2   2017-12-13 CRAN (R 3.5.0)
#>  base      * 3.5.1   2018-07-02 local         
#>  compiler    3.5.1   2018-07-02 local         
#>  datasets  * 3.5.1   2018-07-02 local         
#>  devtools    1.13.6  2018-06-27 CRAN (R 3.5.1)
#>  digest      0.6.16  2018-08-22 CRAN (R 3.5.1)
#>  evaluate    0.11    2018-07-17 CRAN (R 3.5.1)
#>  graphics  * 3.5.1   2018-07-02 local         
#>  grDevices * 3.5.1   2018-07-02 local         
#>  htmltools   0.3.6   2017-04-28 CRAN (R 3.5.0)
#>  knitr       1.20.12 2018-08-13 local         
#>  magrittr    1.5     2014-11-22 CRAN (R 3.5.0)
#>  memoise     1.1.0   2017-04-21 CRAN (R 3.5.0)
#>  methods   * 3.5.1   2018-07-02 local         
#>  Rcpp        0.12.18 2018-07-23 CRAN (R 3.5.1)
#>  rmarkdown   1.10    2018-06-11 CRAN (R 3.5.0)
#>  rprojroot   1.3-2   2018-01-03 CRAN (R 3.5.0)
#>  stats     * 3.5.1   2018-07-02 local         
#>  stringi     1.2.4   2018-07-20 CRAN (R 3.5.1)
#>  stringr     1.3.1   2018-05-10 CRAN (R 3.5.0)
#>  tools       3.5.1   2018-07-02 local         
#>  utils     * 3.5.1   2018-07-02 local         
#>  withr       2.1.2   2018-03-15 CRAN (R 3.5.0)
#>  xfun        0.3     2018-07-06 CRAN (R 3.5.1)
#>  yaml        2.2.0   2018-07-25 CRAN (R 3.5.1)

Created on 2018-08-29 by the reprex package (v0.2.0.9000).

from hrbrthemes.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.