Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dev.args ignored unless wrapped in a list with device names as element names, even with only one device #2238

Closed
3 tasks done
petrbouchal opened this issue Mar 5, 2023 · 2 comments
Labels
bug Bugs

Comments

@petrbouchal
Copy link

When setting a device document-wide, the dev.args only has effect if passed in the form of dev.args = list(device_name = list(option_1 = "x")); when set as dev.args = list(option_1 = "x"), the argument is ignored.

This applies also when only one device is set in dev.

This is surprising given that the documenation states the former usage as necessary only when multiple devices are used (and can be interpreted that when multiple devices are set, the dev.args list would apply to both devices unless set as list(dev_1 = list(...), dev_2 = list(...))).

The reprex below explores the resulting files when

  1. dev.args is set without the list structure (dev.args is ignored)
  2. dev.args is a list with one element, named after the single device (this works)
  3. the same arguments are passed to the device directly, for confirmation

Reprex

---
title: "dev.args passed to svglite"
output: 
  html_document:
    self_contained: false
---

```{r setup, include=FALSE}
library(ggplot2)
library(svglite)
```

## Set `dev.args` as named list for the single device

```{r set-devargs-using-list, include=FALSE}
knitr::opts_chunk$set(echo = TRUE, dev = "svglite",
                      comment = "",
                      dev.args = list(svglite = list(web_fonts = list("https://fonts.googleapis.com/css2?family=IBM+Plex+Sans:ital,wght@0,400;0,700;1,400;1,700&display=swap",
                                  "https://fonts.googleapis.com/css2?family=IBM+Plex+Sans+Condensed:ital,wght@0,400;0,700;1,400;1,700&display=swap"))))
```

### Make plot

```{r}
plt <- ggplot(mtcars) +
  annotate("text", label = "FFf gjfsgd fdshfdsk", x = .5, y = .5, family = "IBM Plex Sans", size = 12)
```

### Render plot

```{r list}
plt
```

### Inspect resulting file

Note the font-related lines that have appeared on lines 5-6 because the argument has been passed through `dev.args`

```{r}
readLines("svgtest_files/figure-html/list-1.svg", n = 15)
```

## Now  set `dev.args` as a list of options

```{r set-devargs-without-list}
knitr::opts_chunk$set(echo = TRUE, dev = "svglite",
                      comment = "",
                      dev.args = list(web_fonts = list("https://fonts.googleapis.com/css2?family=IBM+Plex+Sans:ital,wght@0,400;0,700;1,400;1,700&display=swap",
                                  "https://fonts.googleapis.com/css2?family=IBM+Plex+Sans+Condensed:ital,wght@0,400;0,700;1,400;1,700&display=swap")))

```

### Render file

```{r generate-svg-no-list}
plt
```

Inspect resulting file - note no font-related lines here

```{r}
readLines("svgtest_files/figure-html/no-list-1.svg", n = 15)
```

## Pass the argument directly to the device

```{r}
svglite("svgtest.svg",
        web_fonts = list("https://fonts.googleapis.com/css2?family=IBM+Plex+Sans:ital,wght@0,400;0,700;1,400;1,700&display=swap",
                                  "https://fonts.googleapis.com/css2?family=IBM+Plex+Sans+Condensed:ital,wght@0,400;0,700;1,400;1,700&display=swap"))
plt
dev.off()
```

### Inspect the file

Again, the arguments have an effect

```{r}
readLines("svgtest.svg", n = 15)
```

Same without the argument

```{r}
svglite("svgtest-noarg.svg")
plt
dev.off()
```

### Inspect the file

Here, the font lines do not appear, as expected

```{r}
readLines("svgtest-noarg.svg", n = 15)
```

Session info

R version 4.2.1 (2022-06-23)
Platform: aarch64-apple-darwin20 (64-bit)
Running under: macOS Ventura 13.3, RStudio 2023.3.0.323

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

Package version:
  askpass_1.1       base64enc_0.1.3   brew_1.0.7        brio_1.1.3        bslib_0.4.0       cachem_1.0.6      callr_3.7.0       cli_3.6.0         clipr_0.8.0      
  clisymbols_1.2.0  commonmark_1.8.0  compiler_4.2.1    cpp11_0.4.3       crayon_1.5.2      credentials_1.3.2 curl_5.0.0        desc_1.4.2        devtools_2.4.3   
  diffobj_0.3.5     digest_0.6.31     ellipsis_0.3.2    evaluate_0.20     fansi_1.0.3       fastmap_1.1.0     fs_1.6.1          gert_1.9.0        gh_1.3.1         
  gitcreds_0.1.2    glue_1.6.2        graphics_4.2.1    grDevices_4.2.1   highr_0.10        htmltools_0.5.4   httr_1.4.4        ini_0.3.1         jquerylib_0.1.4  
  jsonlite_1.8.0    knitr_1.42.3      lifecycle_1.0.3   magrittr_2.0.3    memoise_2.0.1     methods_4.2.1     mime_0.12         openssl_2.0.3     pillar_1.8.1     
  pkgbuild_1.3.1    pkgconfig_2.0.3   pkgload_1.2.4     praise_1.0.0      prettyunits_1.1.1 processx_3.6.1    prompt_1.0.1      ps_1.7.1          purrr_1.0.1      
  R6_2.5.1          rappdirs_0.3.3    rcmdcheck_1.4.0   rematch2_2.1.2    remotes_2.4.2     reprex_2.0.2      rlang_1.0.6       rmarkdown_2.16    roxygen2_7.2.1   
  rprojroot_2.0.3   rstudioapi_0.14   rversions_2.1.1   sass_0.4.2        sessioninfo_1.2.2 stats_4.2.1       stringi_1.7.8     stringr_1.5.0     sys_3.4          
  testthat_3.1.6    tibble_3.1.8      tinytex_0.42      tools_4.2.1       usethis_2.1.6     utf8_1.2.2        utils_4.2.1       vctrs_0.5.2       waldo_0.4.0      
  whisker_0.4       withr_2.5.0       xfun_0.37         xml2_1.3.3        xopen_1.0.0       yaml_2.3.7        zip_2.2.2        

By filing an issue to this repo, I promise that

  • I have fully read the issue guide at https://yihui.org/issue/.
  • I have provided the necessary information about my issue.
    • If I'm asking a question, I have already asked it on Stack Overflow or RStudio Community, waited for at least 24 hours, and included a link to my question there.
    • If I'm filing a bug report, I have included a minimal, self-contained, and reproducible example, and have also included xfun::session_info('knitr'). I have upgraded all my packages to their latest versions (e.g., R, RStudio, and R packages), and also tried the development version: remotes::install_github('yihui/knitr').
    • If I have posted the same issue elsewhere, I have also mentioned it in this issue.
  • I have learned the Github Markdown syntax, and formatted my issue correctly.

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

@yihui yihui added the bug Bugs label May 22, 2023
@yihui yihui closed this as completed in 5e7fce8 May 22, 2023
@yihui
Copy link
Owner

yihui commented May 22, 2023

Should be fixed now. Thanks for the report!

Copy link

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 22, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Bugs
Projects
None yet
Development

No branches or pull requests

2 participants