-
-
Notifications
You must be signed in to change notification settings - Fork 878
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
Support out.width|height|extra for office outputs #1746
Conversation
Among |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great! I have hoped to do this two years ago: #1478. Thanks a lot for the help!
@jkr Is there a chance that you could support the |
Cancelled the Travis build as I forgot to skip it via commit message. |
For reference, there is an open issue in pandoc about attributes for pptx image links. see jgm/pandoc#4586 |
I don't understand how to include this in my code. I tried to put in inside a code chunk and run it but nothing changes and i need to resize a plot (from ggplot) to an MS output without ruin it. |
Give me reproducible example to help you. It works under my environment. Example Rmd
|
I was reading yesterday that this has something to be with the hook function from knitr package but i have no idea of how include that in my code. I took your example but it doesn't work in my environment. I don't know if I have to load something or configure anything in my Rstudio. I tried to put this whole code inside a chunk but it doesn't work: I took the reference from here: https://yihui.name/knitr/hooks/ but I still dont understand how to include the hooks in my enviroment or something. It has to be put in a chunk or inline or how? Thanks for the help. |
I think requirements are latest knitr on GitHub, and possibly Pandoc version. You can check the latter by
Is this something you do? knitr::knit_hooks$set(
plot = knitr:::hook_plot_md_pandoc
) |
I was definitely not doing that. I have pandoc version 2.7.3 and Knitir 1.24 I tried to put your suggestion inside a chunk and it says "object 'hook_plot_md_pandoc' not found". I'm sorry to bother with this kind of newbie questions but I can't get the whole rmarkdown trick yet. What should I do? Is there somethin that i have to install? This is simply what I'm trying to do:
Thanks again for your help. |
@irad94 when you want to use a very new feature that has just be added (like this one which just has been merged), you need to install and work with the last development version. remotes::install_github("yihui/knitr") Then you can use the feature. As you see in comment above, you just have to use the chunk option to set a size ---
output: word_document
---
```{r}
ggplot2::qplot(1,1)
```
```{r, out.width=100, out.height=100}
ggplot2::last_plot()
``` There is no need here to set some hook. Generally, you can't take some internal from a PR and apply it to your current code with ease. I would advice to just install the last dev version of knitr and try as @atusy showed you. Hope it helps |
Thank you very much! I didn't know that. I have no much time since started to learn about all this world and I really thank your advice. This really worked for me. Thanks to all of you. |
This PR implments
hook_plot_md_pandoc()
and adds support forout.width
,out.height
, andout.extra
for office outputs (e.g.,rmarkdown::word_document
). It will close #1478.Pandoc supports resizing images via
link_attributes
extention (https://www.pandoc.org/MANUAL.html#images).For example,
will resize "foo.png" to 300 pixels by 300 pixels.
Thus, I decided to assign
out.width
andout.height
towidth
andheight
attributes within curly braces{}
.I also decided to put
out.extra
into curly braces, so that we can use it when Pandoc implements some more features vialink_attributes
.fig.align
is still not supported and thus is coerced to "default" with warning when specified.Example
Output Docx
Source Rmd