knitr icon indicating copy to clipboard operation
knitr copied to clipboard

`dpi` in `include_graphics` is not used for docx output

Open cderv opened this issue 1 year ago • 1 comments

https://github.com/yihui/knitr/blob/4510c09120c9f137859c9c56f497f9de6d92961f/R/plot.R#L502-L506

It seems we don't use dpi calculation for width for other than latex or html.

This is used here to set the out.width https://github.com/yihui/knitr/blob/4510c09120c9f137859c9c56f497f9de6d92961f/R/output.R#L610-L611

---
title: Test
output: word_document
---

```{r}
knitr::include_graphics("pyramide_age_qdl_2.jpeg", dpi = 192)
```

With this file pyramide_age_qdl_2.jpeg

It gives this markdown with no width

![](pyramide_age_qdl_2.jpeg)

setting out.width=500 for example will lead to

![](pyramide_age_qdl_2.jpeg){width=500}

which works in Pandoc thanks to link_attributes extension

For office document we use hook_plot_md_pandoc https://github.com/yihui/knitr/blob/4510c09120c9f137859c9c56f497f9de6d92961f/R/hooks-md.R#L16-L26 Which support width https://github.com/yihui/knitr/blob/4510c09120c9f137859c9c56f497f9de6d92961f/R/hooks-md.R#L118-L135

Maybe we should support this ?

cderv avatar Dec 06 '24 10:12 cderv

Yes, I think so.

yihui avatar Dec 06 '24 19:12 yihui