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

multiple devices error #2373

Merged
merged 2 commits into from
Oct 17, 2024
Merged

multiple devices error #2373

merged 2 commits into from
Oct 17, 2024

Conversation

gaospecial
Copy link
Contributor

When set dev = c("png","pdf"), it will cause a error:

Error in suffix != "" && TRUE : 'length = 2' in coercion to 'logical(1)'

This PR fixed this problem.

@CLAassistant
Copy link

CLAassistant commented Oct 16, 2024

CLA assistant check
All committers have signed the CLA.

Copy link
Owner

@yihui yihui left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This sounds reasonable, but I don't know how to reproduce the problem. I tested a simple code chunk and didn't see the error:

```{r, dev=c('png', 'pdf')}
plot(1)
```

Thanks!

R/utils.R Outdated Show resolved Hide resolved
@gaospecial
Copy link
Contributor Author

gaospecial commented Oct 17, 2024

I can't reproduce it, either. But I finally figured it out, because I added a opts_hook() to include download links in figure captions.

knitr::opts_chunk$set(
  fig.align = "center",
  warning = FALSE,
  message = FALSE,
  dev = c("png","pdf"),
  fig.ext = c("png", "pdf"),
  fig.width = 6.5,
  fig.asp = 0.618,
  fig.align = "center"
)

# add opts_hooks
knitr::opts_hooks$set(dev = function(options){
  if (length(options$dev) > 1){
    x = paste0("[", options$dev, "](", knitr::fig_path(options$dev), ")",
               collapse = " | ")
    options$fig.cap = paste(options$fig.cap, x, sep = " ")
  }
  options
})

It is my problem. I guess that knitr itself doesn't pass options$dev directly to fig_path(). It is knitter.

Co-authored-by: Yihui Xie <[email protected]>
@gaospecial gaospecial closed this Oct 17, 2024
@yihui
Copy link
Owner

yihui commented Oct 17, 2024

Even if it's your problem, I think the code change in this PR will be an improvement (the operation on suffix has been vectorized), so I'll merge it anyway.

@yihui yihui reopened this Oct 17, 2024
@gaospecial
Copy link
Contributor Author

OK. I agree. ^_^

@yihui yihui merged commit c8f3a6d into yihui:master Oct 17, 2024
18 of 19 checks passed
@gaospecial gaospecial deleted the patch-1 branch October 17, 2024 04:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants