davidgohel / officedown Goto Github PK
View Code? Open in Web Editor NEWHome Page: https://ardata-fr.github.io/officeverse/officedown-for-word.html
License: Other
Home Page: https://ardata-fr.github.io/officeverse/officedown-for-word.html
License: Other
Given two predominate formats for source documents to be knitted (1) .Rmd RMarkdown files and (2) .R R scripts, knitting fails when the source document is .R and the output format is officedown::rdocx_document.
.Rmd Style
---
output: officedown::rdocx_document
---
```{r}
mtcars
```
.R Style
#' ---
#' output: officedown::rdocx_document
#' ---
mtcars
Calling rmarkdown::render() on .Rmd style documents succeeds for both the word_document and officedown::rdocx_document output formats.
Calling rmarkdown::render() on .R style documents succeeds for the word_document output format, but fails for officedown::rdocx_document format documents.
.Rmd | .R | |
---|---|---|
word_document | Success | Success |
rdocx_document | Success | Fail |
# Success
rmarkdown::render('reprex.Rmd', encoding = 'UTF-8', output_format = 'officedown::rdocx_document')
reprex.Rmd ->
(@314) reprex.knit.md ->
(@361) reprex.utf8.md ->
(@452) repres.docx
# Success
rmarkdown::render('reprex.R', encoding = 'UTF-8', output_format = 'word_document')
reprex.R ->
(@92) reprex.spin.R ->
(@94) reprex.spin.Rmd ->
(@314) reprex.knit.md ->
(@361) reprex.utf8.md ->
(@452) repres.docx
# Failure
rmarkdown::render('reprex.R', encoding = 'UTF-8', output_format = 'officedown::rdocx_document')
reprex.R ->
(@92) reprex.spin.R ->
(@94) reprex.spin.Rmd ->
(@314) reprex.knit.md ->
FAIL
Error in file(con, "r") : cannot open the connection
In addition: Warning message:
In file(con, "r") :
cannot open file 'reprex.spin.knit.md': No such file or directory
The failure case occurs when rmarkdown::render() calls officedown's post_knit hook with input_file = "reprex.spin.Rmd"
Line 342 in abac21a
The hook code creates an expected output_file value of "reprex.spin.knit.md", which doesn't exist.
I would prep a PR, but I'm not sure how best to handle this without breaking any other execution paths or being hackish about the expected output filename.
Component | Versions |
---|---|
OS | both MacOS and Windows 10 |
R | 3.6.3 and 4.0.3 |
knitr | 1.30 |
rmarkdown | 2.5 |
officedown | 0.2.1.0 |
officer | 0.3.15 |
I was trying to edit the character style "Verbatim Char" in my Word instances (2010 and 2017) but I could not find it in the formatting styles dialogues, also not under a corresponding German style name.
So I was looking what to do, and found that it is much easier to just edit the word/styles.xml file, look for "Verbatim Char" and change the size "sz" from 22 to 20 and - voilá - the R code looks better and has less irritating line breaks.
I was wondering if this could be made configurable... I did not find an option in pandoc or rmarkdown, so I am filing the issue here, because this is the package I am actually using.
Hello,
I'm experiencing some challenges getting multilevel lists to render with proper formatting in Word using officedown. Most notably, when I've organized a multilevel list and seek to render it using pandoc.list(), the following occurs:
As you can see, the code renders appropriately for single level lists (like Subsection2 etc), but perverts the formatting for Section1 in both background color and bullet points.
Additionally, if I go into the created word doc and manually delete / re-enter the space between the beginning point and asterisk, a bullet automatically forms and even adjusts some of the odd formatting (ie that beige highlight behind the words).
Most curiously, as I was preparing this example, I noticed that for three-tiered lists this is not an issue. See below for an example in "Section7", where the bullets align with what is outlined in the reference document:
The only difference I have noted on this is that Section7 contains no trailing whitespace in the Word doc, while the others do - however, I have a call to trimws() prior to adding these points to the list, so it should not be programming it that way. Furthermore, I have tried to set pandoc.list's argument "loose" to TRUE, which only produces the same above formatting for the misaligned lists, and seems to create more of a double-spaced format for the correctly adhering lists.
Any thoughts would be helpful, as I've seen issues raised around this spacing issue in only one issue (here on pandoc's github page), but found none that detail using pandoc lists for multilvel bullet points or numbered lists with any ease. I've also tried multiple reference documents, and even attempted to manually re-create pandoc.list as a function with formatting to my desired specifications, to no avail.
Thanks so much!
Please see my attached files for further reference and full code, dummy data and referenced Word document.
Results of my sessionInfo() call:
Note - I am working with R 4.0, but I am on my work computer and using our RStudio server, and while we recently updated, I may not have full authorization to update to some of the latest CRAN packages.
Hi
Do you mind to give a list of accepted arguments and the correct syntax?
I tried this but it doesn't work. Your examples from readme works fine in my document, so I guess I have no problem else than syntax.
Thanks
I want to write rmd and place the result inside a table with predefined column-widths.
At the moment a code chunk for a flextable seems to be the only option at hand.
I designed a "pandoc-only-template" which should be used to get the right locations for the flextable. However, this has no effect on the flextable. Perhaps there is a solution with ph_with inside the chunk? But what to do with the "x" argument, since we are inside/generating an rpptx object via rmd-file.
ft1 <- flextable(head(iris))
arrW <- dim_pretty(ft1)
ft1 <- width(ft1, width = arrW$widths)
ft1
# has not effect
Cheers
is it possible to still call a template style file as it is in the usual
word_doc output
e.g.
output:
word_document:
reference_docx: ../styleref/my_style.docx
thank you
Hi,
I'm generating reports based on collected data using markdown. The script was developed and test in Autumn 2020. When running the code again yesterday, I experienced an issue with headings being numbered twice see screenshot:
. When creating a pdf or HTML report, the sections are only numbered once.
My header is
---
title: "Michelle SNA Report"
#author: "Katerina Bohle Carbonell"
# output for html in report_v3.Rmd
date: "5th Feb 2021"
always_allow_html: true
output:
bookdown::markdown_document2:
base_format: officedown::rdocx_document
toc: true
---
and r setup is
knitr::opts_chunk$set(
echo = FALSE, message = FALSE, warning = FALSE, eval = TRUE,
fig.width = 7, #width = 8 --> figure outside word margin; width = 7 --> figure cut off
#fig.height = 8,
fig.align = 'center',
dpi = 300
)
R version 3.5.2 (2018-12-20)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS Sierra 10.12.6
Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.5/Resources/lib/libRlapack.dylib
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
[6] methods base
loaded via a namespace (and not attached):
[1] pillar_1.4.7 compiler_3.5.2 tools_3.5.2
[4] digest_0.6.27 jsonlite_1.7.2 evaluate_0.14
[7] lifecycle_0.2.0 tibble_3.0.4 gtable_0.3.0
[10] viridisLite_0.3.0 pkgconfig_2.0.3 rlang_0.4.10
[13] cli_2.2.0 rstudioapi_0.13 yaml_2.2.1
[16] xfun_0.20 dplyr_1.0.2 httr_1.4.2
[19] knitr_1.30 generics_0.1.0 vctrs_0.3.6
[22] htmlwidgets_1.5.3 grid_3.5.2 tidyselect_1.1.0
[25] glue_1.4.2 data.table_1.13.6 R6_2.5.0
[28] fansi_0.4.1 plotly_4.9.3 bookdown_0.21
[31] rmarkdown_2.6 startup_0.15.0 ggplot2_3.3.3
[34] purrr_0.3.4 tidyr_1.1.2 magrittr_2.0.1
[37] scales_1.1.1 ellipsis_0.3.1 htmltools_0.5.0
[40] assertthat_0.2.1 colorspace_2.0-0 lazyeval_0.2.2
[43] munsell_0.5.0 crayon_1.3.4
The template which one can open via the RStudio GUI (file --> new --> R Markdown --> Advanced Word Document) will not knit. I did not alter the document template at all; if I use Ctrl + Shift + k
rmarkdown
throws an error:
Quitting from lines 73-74 (officedown-word-doc-template.Rmd)
Error: read_docx only support docx files
I just downloaded the package today using `install.packages("officedown") so it should be version 0.2.0 .
Here are the results of running sessionInfo()
:
locale:
[1] LC_COLLATE=English_United States.1252
[2] LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C
[5] LC_TIME=English_United States.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods
[7] base
loaded via a namespace (and not attached):
[1] Rcpp_1.0.5 digest_0.6.26 R6_2.4.1
[4] magrittr_1.5 officedown_0.2.0 evaluate_0.14
[7] zip_2.1.1 gdtools_0.2.2 rlang_0.4.8
[10] uuid_0.1-4 xml2_1.3.2 rmarkdown_2.4
[13] tools_4.0.3 officer_0.3.15.005 xfun_0.18
[16] yaml_2.2.1 compiler_4.0.3 systemfonts_0.3.2
[19] rvg_0.2.5 memoise_1.1.0 htmltools_0.5.0
[22] knitr_1.30
Any assistance would be greatly appreciated.
Quitting from lines 31-32 (test.rmd)
Error in if (layout == "full_slide") { : argument is of length zero
Calls: ... knit_print.dml -> get_content_layout -> withVisible -> _f
Execution halted
dml(plot(pressure))
R version 3.5.1 (2018-07-02)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS 10.15
what's wrong?
When submitting a new issue:
Provide the code that is producing the error, it has to be a minimal reproducible example.
Stackoverflow is providing good explanations about it: https://stackoverflow.com/help/mcve. You can use package reprex
to help you: http://reprex.tidyverse.org/. The most popular R stackoverflow question is about the subject: https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example.
Provide the results of R command sessionInfo()
. It had to be executed after you loaded the packages used by your example. This will let me know what is your version of R and what are the versions of the packages you used in your example.
Make sure you did checked you had the latest version of the package on CRAN (and on github if issue exists with CRAN version).
Make sure you searched in the open and closed issues on the github repository.
Hi,
First, thanks for officedown/officer and other amazing packages. I am having an issue rendering word documents, I'm not 100% sure if this is an officedown issue or perhaps rmarkdown/knitr. For reference, I'm using v 0.2.0 from CRAN. This is possibly related to #31.
If the author yaml field includes an ampersand, I receive the following error after the word document is rendered:
Click "OK" and get the following:
Click "Yes" and it will open as a new (unsaved) word document, and everything looks good. I just have to save as a new file.
Here is the .Rmd that I directly knit from:
---
author:
- First Author ^1,a^, Second Author ^1^
- ^a^ Texas A&M University
- ^a^ Corresponding author, [email protected]
title: "Something about *Escherichia coli*"
abstract: |
| This is the abstract.
|
| It consists of two paragraphs.
output:
officedown::rdocx_document
---
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla eu pulvinar arcu, quis aliquam dui. In at cursus ante. Vestibulum non sagittis lacus. Duis vitae iaculis dui. Vivamus tempor, nibh ut pretium tempus, enim lorem dignissim quam, at euismod massa magna at magna.
If I remove the ampersand it knits just fine and produces an error free word doc. I've tried different combinations of escaping the ampersand, quotes, etc.
The corrupted file is attached:
demo.docx
R version 3.6.2 (2019-12-12)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 18363)
Matrix products: default
locale:
[1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252 LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C LC_TIME=English_United States.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
[1] Rcpp_1.0.5 packrat_0.5.0 digest_0.6.25 R6_2.4.1 magrittr_1.5 officedown_0.2.0 evaluate_0.14
[8] zip_2.1.1 gdtools_0.2.1 rlang_0.4.7 uuid_0.1-4 xml2_1.3.2 rmarkdown_2.3 tools_3.6.2
[15] officer_0.3.15 xfun_0.15 yaml_2.2.0 compiler_3.6.2 systemfonts_0.3.2 rvg_0.2.4 memoise_1.1.0
[22] htmltools_0.5.0 knitr_1.29
Could you please change the output from rmarkdown::word_document to bookdown::word_document2?.
The latter output format is better at handling equation numbering and cross-references. Thank you a lot.
When using sections blocks with BLOCK_LANDSCAPE_START and BLOCK_LANDSCAPE_STOP, I have noticed that the reference document's header and footer content will only get displayed in the last section (because Word's "Link to previous" option is disabled in all headers and footers). Is there a way to change this behavior? Maybe it would be possible to add this as an argument to the section blocks?
An easy way to replicate the issue:
rmarkdown::render_site("bookdown")
I tried to make the captions linked to section number as suggested by the doc: https://ardata-fr.github.io/officeverse/officedown-for-word.html#illustrations.
However, it seems to be a continous sequence across all sections. For example, 1.1, 1.2, 2.3, 2.4, 3.5. I want to set the figure id from 1 for every chapter, such as 1.1, 1.2, 2.1, 2.2, 3.1.
To get it, I did a trick that is to define different run_autonum
functions (such as runs_fig1
) for each chapter and then reference it by r run_bookmark("fig-id", runs_fig1)
.
run_autonum
functions for example in the first chapter
runs_fig1 <- list(
run_word_field("STYLEREF 1 \\s"),
ftext("."),
run_autonum(seq_id = "fig1", pre_label = "", post_label = "")
)
reference the figure
`
plot(iris[, 4:5])
`
::: {custom-style="Image Caption"}
图 `r bkm("iris", runs_fig1)` plot of iris
:::
Reference of \@ref(fig:iris)
I'v created a demo test at https://github.com/bishun945/officedown_test
After building it, it seems work but the toc list is divided into different parts.
block_toc(seq_id = c("fig1", "fig2"))
I also tried to block_toc
by style
but the custom-style of table or figure has two different styles in my actual project.
Is there any better solution to get that?
Thank you very much.
> sessionInfo()
R version 3.6.2 (2019-12-12)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19041)
Matrix products: default
locale:
[1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C
[5] LC_TIME=English_United States.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
[1] compiler_3.6.2 bookdown_0.21 R6_2.5.0 htmltools_0.5.1.1 tools_3.6.2
[6] yaml_2.2.1 uuid_0.1-4 xml2_1.3.2 officer_0.3.17.001 rmarkdown_2.6
[11] knitr_1.31 xfun_0.21.1 digest_0.6.27 zip_2.1.1 rlang_0.4.10
[16] evaluate_0.14
When I knit an Rmd file with officedown::rpptx_document
, the function produces an unopenable pptx file with the following error message:
PowerPoint found a problem with content in xxxx.pptx.
PowerPoint can attempt to repair the presentation.
I confirmed that the contents of the Rmd are knittable with, for eaxample, bookdown::powerpoint_presentation2
. Therefore, I suspect some bugs might lie in officedown::rpptx_document
.
---
title: "Untitled"
author: "CLRR"
date: "2020/6/20"
output:
officedown::rpptx_document:
keep_md: TRUE
bookdown::powerpoint_presentation2:
keep_md: TRUE
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
```
## R Markdown
This is an R Markdown presentation. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>.
When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document.
## Slide with Bullets
- Bullet 1
- Bullet 2
- Bullet 3
## Slide with R Output
```{r cars, echo = TRUE}
summary(cars)
```
## Slide with Plot
```{r pressure}
plot(pressure)
```
rmarkdown::pandoc_version()
[1] ‘2.9.2.1’
R version 4.0.0 (2020-04-24)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 18362)
Matrix products: default
locale:
[1] LC_COLLATE=Japanese_Japan.932 LC_CTYPE=Japanese_Japan.932 LC_MONETARY=Japanese_Japan.932 LC_NUMERIC=C LC_TIME=Japanese_Japan. 932
attached base packages:
[1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
Rcpp_1.0.4.6
packrat_0.5.0
digest_0.6.25
R6_2.4.1
magrittr_1.5
officedown_0.1.0
evaluate_0.14
zip_2.0.4
gdtools_0.2.2
rlang_0.4.6
uuid_0.1-4
xml2_1.3.2
rmarkdown_2.2
tools_4.0.0
officer_0.3.11
xfun_0.14
yaml_2.2.1
compiler_4.0.0
systemfonts_0.2.3 r
vg_0.2.4
memoise_1.1.0
htmltools_0.4.0
knitr_1.28
All .Rd titles should:
In my Rmd, I cannot seem to get officedown to abide by the styles I set out in reference.docx, specifically numbered sections. The numbersections: yes
bit in YAML below halts compilation with following:
---
bibliography: ../../full_zotero_bibliography.bib
fontfamily: times
lang: en-US
#numbersections: yes
output:
#bookdown::word_document2
officedown::rdocx_document:
reference_docx: ../../reference.docx
#numbersections: yes
---
Error:
Error in (function (toc = FALSE, toc_depth = 3, number_sections = FALSE, :
unused argument (numbersections = TRUE)
Calls: <Anonymous> ... create_output_format -> do.call -> <Anonymous> -> do.call
Execution halted
That's all the info RStudio is giving me. But, the error is the same regardless of whether it's numbersections
or numberSections
, whether it's child of officedown::rdocx_document or same level. The Table of Contents generates correctly, but without level numbering, so I know the headers are correct. I also know the reference.docx is correctly styled, because bookdown::word_document2 correctly numbers sections. (But with bookdown::word_document2, there are no numbered pages! If you have insight about that, I'd like to hear it.)
Hi,
first of all thanks for this very nice and helpful combination of officer and rmarkdwon/bookdown!
I just came across the package when searching a proper way to get a column-output in word.
I managed to make use of the functionality.
However, even with simplest doxc-output I encounter one or more error messages on first opening the doxc-file in word.
A reproducible example is
---
title: test
output:
bookdown::markdown_document2:
base_format: officedown::rdocx_document
---
[link to officedown](https://davidgohel.github.io/officedown/articles/yaml.html)
\@ref(ref-01)
# h1 {#ref-01}
How to avoid the corrupted docx-files?
Further:
And one setting (always on W10) when inserting the @ref() SLOC the link above of it gets destroyed.
I have to check this again, in order to make a reproducible example of the phenomenon.
Cheers
Not a bug or feature request? If you are looking for help on how to use the
package correctly, please read the doc first at https://davidgohel.github.io/officedown/.
You can also visit Stackoverflow
and tag your question with [officedown]
. We usually read them and answer WHEN possible.
When submitting a new issue:
I have a table inside my RMarkdown document that uses symbols. These are not generated when I knit my document. Curious if anyone has a workaround. I created a reprex using the default template for officedown and created a table
---
date: "`r Sys.Date()`"
author: "Your Name"
title: "officedown template"
output:
officedown::rdocx_document:
mapstyles:
Normal: ['First Paragraph']
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE, fig.cap = TRUE)
library(officedown)
library(officer)
fp <- fp_par(
text.align = "center",
padding.bottom = 20, padding.top = 120,
border.bottom = fp_border())
ft <- fp_text(shading.color='#EFEFEF', bold = TRUE)
myTable <- data.frame(list = c("A", "B"),
id = c("A→B", "C→D"))
\newpage
Table \@ref(tab:myTable)
```{r tab.cap="caption 1", tab.id="myTable"}
myTable
sessionInfo is shown below
sessionInfo()
R version 3.6.3 (2020-02-29)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19041)
Matrix products: default
locale:
[1] LC_COLLATE=English_Canada.1252 LC_CTYPE=English_Canada.1252 LC_MONETARY=English_Canada.1252 LC_NUMERIC=C LC_TIME=English_Canada.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
[1] pacman_0.5.1 tidyselect_1.1.0 lme4_1.1-23 htmlwidgets_1.5.2 grid_3.6.3 gmp_0.6-0 jtools_2.1.0
[8] munsell_0.5.0 codetools_0.2-16 effectsize_0.3.3 statmod_1.4.34 miniUI_0.1.1.1 withr_2.3.0 Brobdingnag_1.2-6
[15] metaBMA_0.6.3 colorspace_1.4-1 uuid_0.1-4 knitr_1.30 rstudioapi_0.11 stats4_3.6.3 DescTools_0.99.38
[22] ipmisc_4.0.0 officer_0.3.14 ggsignif_0.6.0 rcompanion_2.3.25 Rttf2pt1_1.3.8 rstan_2.21.2 bbmle_1.0.23.1
[29] bridgesampling_1.0-0 coda_0.19-4 vctrs_0.3.4 generics_0.0.2 TH.data_1.0-10 tidyBF_0.3.0 metafor_2.4-0
[36] xfun_0.17 BWStest_0.2.2 R6_2.4.1 BayesFactor_0.9.12-4.2 logspline_2.1.16 reshape_0.8.8 assertthat_0.2.1
[43] promises_1.1.1 scales_1.1.1 multcomp_1.4-14 nnet_7.3-12 ggExtra_0.9 rootSolve_1.8.2.1 gtable_0.3.0
[50] multcompView_0.1-8 processx_3.4.4 lmom_2.8 sandwich_3.0-0 rlang_0.4.7 MatrixModels_0.4-1 EMT_1.1
[57] zeallot_0.1.0 systemfonts_0.3.2 Rmisc_1.5 PMCMRplus_1.5.0 splines_3.6.3 extrafontdb_1.0 TMB_1.7.18
[64] inline_0.3.16 broom_0.7.1 checkmate_2.0.0 yaml_2.2.1 reshape2_1.4.4 abind_1.4-5 backports_1.1.10
[71] httpuv_1.5.4 extrafont_0.17 tools_3.6.3 ggplot2_3.3.2 ellipsis_0.3.1 WRS2_1.1-0 ez_4.4-0
[78] Rcpp_1.0.5 plyr_1.8.6 purrr_0.3.4 prettyunits_1.1.1 ps_1.3.4 pbapply_1.4-3 cowplot_1.1.0
[85] correlation_0.4.0 zoo_1.8-8 LaplacesDemon_16.1.4 haven_2.3.1 ggrepel_0.8.2 hrbrthemes_0.8.0 survey_4.0
[92] magrittr_1.5 data.table_1.13.0 openxlsx_4.2.2 lmtest_0.9-38 effects_4.2-0 mvtnorm_1.1-1 broomExtra_4.0.6
[99] matrixStats_0.56.0 hms_0.5.3 mime_0.9 evaluate_0.14 xtable_1.8-4 rio_0.5.16 pairwiseComparisons_3.0.0
[106] broom.mixed_0.2.6 readxl_1.3.1 rstantools_2.1.1 gridExtra_2.3 compiler_3.6.3 bdsmatrix_1.3-4 tibble_3.0.3
[113] V8_3.2.0 ggstatsplot_0.6.1 crayon_1.3.4 StanHeaders_2.21.0-6 minqa_1.2.4 htmltools_0.5.0 mgcv_1.8-31
[120] mc2d_0.1-18 later_1.1.0.1 tidyr_1.1.2 libcoin_1.0-6 expm_0.999-5 RcppParallel_5.0.2 Exact_2.1
[127] lubridate_1.7.9 DBI_1.1.0 SuppDists_1.1-9.5 kSamples_1.2-9 sjlabelled_1.1.5 MASS_7.3-51.5 boot_1.3-24
[134] Matrix_1.2-18 car_3.0-9 cli_2.1.0 mitools_2.4 parallel_3.6.3 insight_0.9.6 forcats_0.5.0
[141] pkgconfig_2.0.3 metaplus_0.7-11 statsExpressions_0.5.1 numDeriv_2016.8-1.1 coin_1.3-1 foreign_0.8-75 xml2_1.3.2
[148] paletteer_1.2.0 expss_0.10.6 ggcorrplot_0.1.3 rvg_0.2.5 snakecase_0.11.0 callr_3.5.1 stringr_1.4.0
[155] digest_0.6.25 parameters_0.8.6 janitor_2.0.1 fastGHQuad_1.0 rmarkdown_2.4 cellranger_1.1.0 htmlTable_2.1.0
[162] nortest_1.0-4 gld_2.6.2 gdtools_0.2.2 curl_4.3 shiny_1.5.0 gtools_3.8.2 modeltools_0.2-23
[169] nloptr_1.2.2.2 jsonlite_1.7.1 lifecycle_0.2.0 nlme_3.1-144 carData_3.0-4 interactions_1.1.3 fansi_0.4.1
[176] pillar_1.4.6 loo_2.3.1 lattice_0.20-38 pkgbuild_1.1.0 fastmap_1.0.1 survival_3.1-12 glue_1.4.2
[183] officedown_0.2.0 bayestestR_0.7.2 zip_2.1.1 pander_0.6.3 class_7.3-15 stringi_1.4.6 performance_0.5.0
[190] rematch2_2.1.2 memoise_1.1.0 Rmpfr_0.8-1 dplyr_1.0.2 e1071_1.7-3 cgwtools_3.2
Hi David,
I'm currently using officedown and it makes life with Word-documents a lot easier within Rmarkdown. Thanks for that!
I would like to produce a figure on a new landscape page by inserting the figure between the respective code-chunks
<!---BLOCK_LANDSCAPE_START--->
knitr::include_graphics("filename.png")
<!---BLOCK_LANDSCAPE_STOP--->
That works like a charm! However, the top- and bottom-margins are 5cm each in the rendered Word-document and I would like to reduce that within Rmarkdown. Any idea how to?
I want to link to a file (or directory) containing special characters:
---
output:
officedown::rdocx_document: default
bookdown::word_document2: default
---
[works](C:/Users/Public)
[doesn't work](C:/Users/Public/Umläüt)
The code produces an invalid docx-file with officedown-0.2.0
, while it does work with bookdown
.
I have encountered a weird bug when using section breaks in combination with the header and footer option "Different First Page" in the template.docx document. The problem may be related to #21, which you have kindly fixed.
Steps to reproduce:
Is there a way to avoid this bug, or is using "Different First Page" simply not supported in combination with section breaks? I did look at the documentation for officer::prop_section
and noticed that there does not appear to be a section type "first page" or similar. I am using this option in the template.docx to have a nicely formatted title page that is separate from the rest of the document (with graphics in the header, a special footer, etc.). Is there an alternative way of achieving that?
library(officedown)
rmarkdown::pandoc_version()
#> [1] '2.7.3'
dir <- system.file(package = "officedown", "examples", "bookdown")
file.copy(dir, getwd(), recursive = TRUE, overwrite = TRUE)
#> [1] TRUE
rmarkdown::render_site("bookdown")
#> processing file: bookdown.Rmd
#> output file: bookdown.knit.md
#> "C:/Program Files/RStudio/bin/pandoc/pandoc" +RTS -K512m -RTS ./index.split.md ./01-intro.split.md ./02-toc.split.md ./03-tables.split.md ./04-sections.split.md ./05-plots.split.md --to docx --from markdown+autolink_bare_uris+tex_math_single_backslash --output bookdown.docx --highlight-style tango --reference-doc template.docx --lua-filter "D:/Data/Documents/R/win-library/4.0/rmarkdown/rmd/lua/pagebreak.lua" --file-scope
#>
#> Output created: _book/bookdown.docx
Created on 2020-07-15 by the reprex package (v0.3.0)
devtools::session_info()
#> - Session info ---------------------------------------------------------------
#> setting value
#> version R version 4.0.2 (2020-06-22)
#> os Windows 10 x64
#> system x86_64, mingw32
#> ui RTerm
#> language (EN)
#> collate German_Germany.1252
#> ctype German_Germany.1252
#> tz Europe/Berlin
#> date 2020-07-15
#>
#> - Packages -------------------------------------------------------------------
#> package * version date lib source
#> assertthat 0.2.1 2019-03-21 [1] CRAN (R 4.0.2)
#> backports 1.1.8 2020-06-17 [1] CRAN (R 4.0.2)
#> base64enc 0.1-3 2015-07-28 [1] CRAN (R 4.0.0)
#> bookdown 0.20 2020-06-23 [1] CRAN (R 4.0.2)
#> callr 3.4.3 2020-03-28 [1] CRAN (R 4.0.2)
#> cli 2.0.2 2020-02-28 [1] CRAN (R 4.0.2)
#> colorspace 1.4-1 2019-03-18 [1] CRAN (R 4.0.2)
#> crayon 1.3.4 2017-09-16 [1] CRAN (R 4.0.2)
#> data.table 1.12.8 2019-12-09 [1] CRAN (R 4.0.0)
#> desc 1.2.0 2018-05-01 [1] CRAN (R 4.0.2)
#> devtools 2.3.0 2020-04-10 [1] CRAN (R 4.0.2)
#> digest 0.6.25 2020-02-23 [1] CRAN (R 4.0.2)
#> dplyr 1.0.0 2020-05-29 [1] CRAN (R 4.0.2)
#> ellipsis 0.3.1 2020-05-15 [1] CRAN (R 4.0.2)
#> evaluate 0.14 2019-05-28 [1] CRAN (R 4.0.2)
#> fansi 0.4.1 2020-01-08 [1] CRAN (R 4.0.2)
#> farver 2.0.3 2020-01-16 [1] CRAN (R 4.0.2)
#> flextable * 0.5.11.007 2020-07-15 [1] Github (davidgohel/flextable@cd9087b)
#> fs 1.4.2 2020-06-30 [1] CRAN (R 4.0.2)
#> gdtools 0.2.2 2020-04-03 [1] CRAN (R 4.0.2)
#> generics 0.0.2 2018-11-29 [1] CRAN (R 4.0.2)
#> ggplot2 * 3.3.2 2020-06-19 [1] CRAN (R 4.0.2)
#> glue 1.4.1 2020-05-13 [1] CRAN (R 4.0.2)
#> gtable 0.3.0 2019-03-25 [1] CRAN (R 4.0.2)
#> highr 0.8 2019-03-20 [1] CRAN (R 4.0.2)
#> htmltools 0.5.0 2020-06-16 [1] CRAN (R 4.0.2)
#> knitr * 1.29 2020-06-23 [1] CRAN (R 4.0.2)
#> labeling 0.3 2014-08-23 [1] CRAN (R 4.0.0)
#> lifecycle 0.2.0 2020-03-06 [1] CRAN (R 4.0.2)
#> magrittr * 1.5 2014-11-22 [1] CRAN (R 4.0.2)
#> memoise 1.1.0 2017-04-21 [1] CRAN (R 4.0.2)
#> munsell 0.5.0 2018-06-12 [1] CRAN (R 4.0.2)
#> officedown * 0.2.1.001 2020-07-15 [1] Github (davidgohel/officedown@abac21a)
#> officer * 0.3.13.005 2020-07-15 [1] Github (davidgohel/officer@88f7851)
#> pillar 1.4.6 2020-07-10 [1] CRAN (R 4.0.2)
#> pkgbuild 1.1.0 2020-07-13 [1] CRAN (R 4.0.2)
#> pkgconfig 2.0.3 2019-09-22 [1] CRAN (R 4.0.2)
#> pkgload 1.1.0 2020-05-29 [1] CRAN (R 4.0.2)
#> prettyunits 1.1.1 2020-01-24 [1] CRAN (R 4.0.2)
#> processx 3.4.3 2020-07-05 [1] CRAN (R 4.0.2)
#> ps 1.3.3 2020-05-08 [1] CRAN (R 4.0.2)
#> purrr 0.3.4 2020-04-17 [1] CRAN (R 4.0.2)
#> R6 2.4.1 2019-11-12 [1] CRAN (R 4.0.2)
#> Rcpp 1.0.5 2020-07-06 [1] CRAN (R 4.0.2)
#> remotes 2.1.1 2020-02-15 [1] CRAN (R 4.0.2)
#> rlang 0.4.7 2020-07-09 [1] CRAN (R 4.0.2)
#> rmarkdown 2.3 2020-06-18 [1] CRAN (R 4.0.2)
#> rprojroot 1.3-2 2018-01-03 [1] CRAN (R 4.0.2)
#> rstudioapi 0.11 2020-02-07 [1] CRAN (R 4.0.2)
#> rvg 0.2.5 2020-06-30 [1] CRAN (R 4.0.2)
#> scales 1.1.1 2020-05-11 [1] CRAN (R 4.0.2)
#> sessioninfo 1.1.1 2018-11-05 [1] CRAN (R 4.0.2)
#> stringi 1.4.6 2020-02-17 [1] CRAN (R 4.0.0)
#> stringr 1.4.0 2019-02-10 [1] CRAN (R 4.0.2)
#> systemfonts 0.2.3 2020-06-09 [1] CRAN (R 4.0.2)
#> testthat 2.3.2 2020-03-02 [1] CRAN (R 4.0.2)
#> tibble 3.0.3 2020-07-10 [1] CRAN (R 4.0.2)
#> tidyselect 1.1.0 2020-05-11 [1] CRAN (R 4.0.2)
#> usethis 1.6.1 2020-04-29 [1] CRAN (R 4.0.2)
#> uuid 0.1-4 2020-02-26 [1] CRAN (R 4.0.0)
#> vctrs 0.3.2 2020-07-15 [1] CRAN (R 4.0.2)
#> withr 2.2.0 2020-04-20 [1] CRAN (R 4.0.2)
#> xfun 0.15 2020-06-21 [1] CRAN (R 4.0.2)
#> xml2 1.3.2 2020-04-23 [1] CRAN (R 4.0.2)
#> yaml 2.2.1 2020-02-01 [1] CRAN (R 4.0.0)
#> zip 2.0.4 2019-09-01 [1] CRAN (R 4.0.2)
#>
#> [1] D:/Data/Documents/R/win-library/4.0
#> [2] C:/Program Files/R/R-4.0.2/library
Hi,
In the demonstration bookdown included with the package, the Table of Figures and Table of Tables do not render but instead report "No table of contents entries found."
(See attached output).
Is there a workaround for this? It's pretty much the only thing stopping me using officedown
in production. (This together with officer
and flextable
represent a phenomenal set of tools, thanks for all the hard work!)
Hi,
I recently switched computers and re-installed my r packages.
I tried to install all my old packages, same versions ans my previous installation, and this worked, instead of officedown, because I had a version which was at the time not available on CRAN yet. This was 0.0.5.003.
With the newer version(s) of officedown available on CRAN, the render statement as was does not work anymore. I tested it with all older versions on CRAN that were available.
When I commented out the intermediates_dir and knit_root_dir, the render statement works again. So something changed/stoppped working in the newer versions. Can you fix this?
I need these two statements, because I run this code on a lamdba, which needs the intermediate files to go to a specified temp folder or else it cannot write files and does not work there.
The used render statement is:
rmarkdown::render(input = markdownTemplate,
officedown::rdocx_document( # more word formatting functionality
reference_docx = referenceDocx
),
output_file = FILENAME,
output_dir = outputDirectory,
intermediates_dir = outputDirectory, # places everything in /tmp file
knit_root_dir = outputDirectory
)
The errors I get with the newer version of officedown (important is 9, the breaking one):
Warning messages:
1: paragraph style for plots "Figure" has not been found in the reference_docx document. Style 'Normal' will be used instead.
2: paragraph style for plots "Figure" has not been found in the reference_docx document. Style 'Normal' will be used instead.
3: paragraph style for plots "Figure" has not been found in the reference_docx document. Style 'Normal' will be used instead.
4: paragraph style for plots "Figure" has not been found in the reference_docx document. Style 'Normal' will be used instead.
5: paragraph style for plots "Figure" has not been found in the reference_docx document. Style 'Normal' will be used instead.
6: paragraph style for plots "Figure" has not been found in the reference_docx document. Style 'Normal' will be used instead.
7: paragraph style for plots "Figure" has not been found in the reference_docx document. Style 'Normal' will be used instead.
8: paragraph style for plots "Figure" has not been found in the reference_docx document. Style 'Normal' will be used instead.
9: In file(con, "r") :
cannot open file 'template_EED_Word.knit.md': No such file or directory
Old version of officedown does not give any warnings or errors with this stamenet and renders the word document flawlessly.
I would also like some pointers on how to avoid warnings 1:8, because this now gives other image formats, that in the old version worked perfectly fine.
My sessionInfo with the old officedown:
sessionInfo()
R version 3.5.3 (2019-03-11)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19041)
Matrix products: default
locale:
[1] LC_COLLATE=English_Netherlands.1252 LC_CTYPE=English_Netherlands.1252 LC_MONETARY=English_Netherlands.1252 LC_NUMERIC=C
[5] LC_TIME=English_Netherlands.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] knitr_1.26 officedown_0.0.5.003 officer_0.3.14 rmarkdown_2.0 aws.s3_0.3.12 flextable_0.5.10 cowplot_1.0.0
[8] png_0.1-7 ggplot2_3.1.0 stringr_1.4.0 tidyr_1.0.2 httr_1.4.0 dplyr_0.8.5 hms_0.5.3
[15] lubridate_1.7.4 config_0.3 jsonlite_1.6 futile.logger_1.4.3
loaded via a namespace (and not attached):
[1] tinytex_0.14 tidyselect_0.2.5 xfun_0.13 purrr_0.3.2 colorspace_1.4-1 vctrs_0.2.4 htmltools_0.3.6
[8] yaml_2.2.0 base64enc_0.1-3 rlang_0.4.5 pillar_1.4.6 glue_1.4.0 withr_2.1.2 gdtools_0.2.2
[15] lambda.r_1.2.3 uuid_0.1-4 lifecycle_0.2.0 plyr_1.8.4 munsell_0.5.0 gtable_0.3.0 zip_2.1.1
[22] memoise_1.1.0 evaluate_0.13 labeling_0.3 curl_3.3 Rcpp_1.0.4.6 scales_1.0.0 formatR_1.6
[29] magick_2.0 systemfonts_0.2.0 digest_0.6.18 stringi_1.4.3 grid_3.5.3 tools_3.5.3 magrittr_1.5
[36] lazyeval_0.2.2 tibble_3.0.3 futile.options_1.0.1 crayon_1.3.4 aws.signature_0.4.4 pkgconfig_2.0.2 ellipsis_0.3.0
[43] data.table_1.13.0 xml2_1.2.0 rvg_0.2.4 assertthat_0.2.1 rstudioapi_0.10 R6_2.4.0 compiler_3.5.3
My sessionInfo with the new officedown:
sessionInfo()
R version 3.5.3 (2019-03-11)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19041)
Matrix products: default
locale:
[1] LC_COLLATE=English_Netherlands.1252 LC_CTYPE=English_Netherlands.1252 LC_MONETARY=English_Netherlands.1252 LC_NUMERIC=C
[5] LC_TIME=English_Netherlands.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] knitr_1.26 officedown_0.2.0 officer_0.3.14 rmarkdown_2.0 aws.s3_0.3.12 flextable_0.5.10 cowplot_1.0.0
[8] png_0.1-7 ggplot2_3.1.0 stringr_1.4.0 tidyr_1.0.2 httr_1.4.0 dplyr_0.8.5 hms_0.5.3
[15] lubridate_1.7.4 config_0.3 jsonlite_1.6 futile.logger_1.4.3
loaded via a namespace (and not attached):
[1] tidyselect_0.2.5 xfun_0.13 purrr_0.3.2 colorspace_1.4-1 vctrs_0.2.4 htmltools_0.3.6 yaml_2.2.0
[8] base64enc_0.1-3 rlang_0.4.5 pillar_1.4.6 glue_1.4.0 withr_2.1.2 gdtools_0.2.2 lambda.r_1.2.3
[15] uuid_0.1-4 lifecycle_0.2.0 plyr_1.8.4 munsell_0.5.0 gtable_0.3.0 zip_2.1.1 evaluate_0.13
[22] memoise_1.1.0 labeling_0.3 curl_3.3 Rcpp_1.0.4.6 scales_1.0.0 formatR_1.6 magick_2.0
[29] systemfonts_0.2.0 digest_0.6.18 stringi_1.4.3 grid_3.5.3 tools_3.5.3 magrittr_1.5 lazyeval_0.2.2
[36] tibble_3.0.3 futile.options_1.0.1 crayon_1.3.4 aws.signature_0.4.4 pkgconfig_2.0.2 ellipsis_0.3.0 data.table_1.13.0
[43] xml2_1.2.0 rvg_0.2.4 assertthat_0.2.1 rstudioapi_0.10 R6_2.4.0 compiler_3.5.3
Hi David,
I am wondering if you could help me with the following issues when using flextable
in officedown
:
I have a list of multiple data frames. I'd like to print each data frame using flextable(list[[i]])
and knit those to a word document. However, the knitr
chunk header only allows me to set an overarching table caption and for
loops don't quite work here. Is there a way to print all tables in the list at once and allow me to customize each table caption?
{r internal_reliability, tab.cap = "Internal reliability", tab.id = "internal_reliability"}
for (i in length(list)) {
flextable(list[[i]]) %>%
align(part = "all") %>%
font(fontname = "Times", part = "all") %>%
bold(part = "header") %>%
fontsize(size = 10, part = "body") %>%
set_table_properties(layout = "autofit")
}
Another issue is that in the table of content, it doesn't show the table id. It would be great if it shows Table 1: Descriptive statistics, and Table 2: Correlation matrix. See my set up below:
---
title: "`r params$set_title`"
author: "`r params$set_author`"
date: "`r Sys.Date()`"
params:
printcode: no
printwarning: no
storecache: yes
set_title: "Report"
set_author: "Michael Wu"
output:
officedown::rdocx_document:
mapstyles:
Normal: ['First Paragraph']
reference_docx: "MR_word_template.docx"
---
```{r setup, include = F}
# knitr global settings
knitr::opts_chunk$set(
echo = TRUE,
fig.cap = TRUE,
echo = params$printcode,
warning = params$printwarning,
cache = params$storecache,
message = F,
error = T,
results="asis",
tab.cap.style = "Table Caption",
tab.cap.pre = "Table ",
tab.cap.sep = ": ",
fig.cap.style = "Image Caption",
fig.cap.pre = "Figure ",
fig.cap.sep = ": ")```
Thank you so much!
Could not list flextable under List of tables in .docx file. can you please suggest a reason or solution?. thanks.
Output:
List of tables
No table of contents entries found.
my code is : <!---BLOCK_TOC{style: 'Image Caption', separator: ','}--->
Hello,
I wasn't sure where to ask this question. I'm new to officedown. To test, I tried the instructions in the main page to generate the bookdown.docx demo file. I'm not getting the same result as the output shown. In particular, references don't seem to work and I don't get the tables of Figures, tables,Contents. Apart from that I'm not getting the nice "Bradley hand" font used in section 5.4 ... I'm guessing the font issue is about a package that I should load with fonts, but I'm not sure about the referencing? I believe I have all it is needed in terms of dependencies of the packages, but I might be missing something? Can't find any extra guidelines in terms of if I need to load any librarys and which order or something... any ideas? help? I'm aware it most be a silly thing on my part.
Thanks
The readme mentions using narrow margins, but I can not find any example of how to do so. Is this only possible with a reference document?
Interested in how to create a chunk to add a new line much like <!---CHUNK_PAGEBREAK---> adds a pagebreak.
Currently seems that table and figures are captioned sequentially 1:n. Is there a way to make the captioning link to the section in which they are located (e.g. Table 3.1, 3.2.. 3.n for tables located in section 3, or even Table A.1, A.2 for tables located in a document appendix), as is possible in Word?
I found this article that explains how to number and reference figures and tables, but it doesn't explain how to do the same with equations. I have tried the bookdown style:
\begin{equation}
f\left(k\right) = \binom{n}{k} p^k\left(1-p\right)^{n-k} (\#eq:binom)
\end{equation}
But it seems officedown doesn't recognize the equation environment.
I think it would be very helpful if you add this topic to the documentation of the project.
Thank you for the great work on this super useful package.
I would like to ask if it is possible to style individual text elements with a style from the template Word document indicated in reference_docx
field in the YAML header.
I know individual text elements can be styled using ftext
and fp_text
e.g.:
Here is some normal text. `r ftext('But this sentence is red', fp_text(color = "red"))`
But instead of using specific font/color etc. properties as argument, is it possible somehow specify a style that is contained in the template/reference Word document?
I have not found any documentation relative to this.
Thanks a lot!
Hi,
I am in the process of creating a mail merge with R Markdown. I have an R script to scan a Contact List which inputs the Rmd document (Letter Template) to produce letters for each individual on the Contact List.
Another loop is written within the Rmd document that reads 3 data frames to produce 3 tables. For example:
So far, everything is producing beautifully but the only problem is the table layout. A letter for each contact may have 2 or more Stores and so, 6 or more tables all with varying numbers of rows.
I was hoping that by incorporating chunk_page_break_ at the end of the loop it would create a new page for the next 3 tables.
I have attempted to create blank space that separates the tables but that does not work well.
Would you be able to assist me with this? Thank you in advance!
When passing fig.scap
to knitr::include_graphics()
, it would be valuable to have this item available and used in the List of Figures, and the same goes for caption.short
with kable for List of Tables. Not sure if this is a bug or a feature request.
Hi,
I just tried the sample rpptx and noticed that the "Two Columns" layout is not applied for generating the output-pptx-file.
Neither for a chunk like in
{r layout='Two Content', ph=officer::ph_location_left()}
nor when changing the YAML.
I am working on Windows 10.
Cheers
Hi there,
At first I would like to say, love your work, you make making word documents so much easier!
I have a table that shows traffic light 'bulbs', that works when I run it locally with RStudio, but does not work on my AWS lambda instance (without R Studio).
The code in my R Markdown document (simplified):
table <- data.frame( "Waardering" = paste0(PATH, "red.png"),
"Naam" = "Tegelijk verwarmen en koelen",
"Waarde" = 11,48)
The flextable call in my R Markdown document:
table %>% flextable() %>%
border_outer(border = fp_border(color = "#50215F", style = "solid", width = 1.5), part = "all") %>%
border_inner(border = fp_border(color = "#50215F", style = "solid", width = 0.5), part = "all") %>%
align(align = "center", part = "header") %>%
font(fontname = "Calibri", part = "all") %>%
fontsize(size = 10, part = "all") %>%
color(color = "#50215F", part = "all") %>%
width(width = 0.6) %>%
align(align = "center") %>%
compose(j = "Waardering", value = as_paragraph(as_image(src = Waardering, width = 10/72, height = 10/72))) %>%
compose(part = "header", j = "Waardering", value = as_paragraph(""))
I render this with officedown::rdocx_document in an R script.
rmarkdown::render(input = markdownTemplate,
officedown::rdocx_document(
reference_docx = referenceDocx
),
output_file = FILENAME,
output_dir = outputDirectory)
Rendering of the word-docx works without problems, except for the images in the table.
My local result is this:
What I tried already:
The difference is already seen in the knit.md files, the path reference in the openXML statement of the table is present in my local version, but is empty in the AWS version. If I open the docx as zips, in my local version the images are included in the word>media file, in the AWS version they are not present.
What could be the problem here?
Local session info:
R version 3.5.2 (2018-12-20)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 18362)
Matrix products: default
locale:
[1] LC_COLLATE=Dutch_Netherlands.1252 LC_CTYPE=Dutch_Netherlands.1252 LC_MONETARY=Dutch_Netherlands.1252 LC_NUMERIC=C
[5] LC_TIME=Dutch_Netherlands.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] flextable_0.5.6 knitr_1.26 officedown_0.0.5.002 officer_0.3.6 rmarkdown_1.17 aws.s3_0.3.12
[7] ggplot2_3.1.0 stringr_1.4.0 tidyr_0.8.3 httr_1.4.0 dplyr_0.8.0.1 hms_0.5.2
[13] lubridate_1.7.4 config_0.3 jsonlite_1.6 futile.logger_1.4.3
loaded via a namespace (and not attached):
[1] Rcpp_1.0.1 prettyunits_1.0.2 ps_1.3.0 assertthat_0.2.1 zeallot_0.1.0 rprojroot_1.3-2
[7] digest_0.6.18 aws.signature_0.4.4 R6_2.4.0 plyr_1.8.4 futile.options_1.0.1 backports_1.1.3
[13] evaluate_0.13 pillar_1.3.1 gdtools_0.2.1 rlang_0.4.2 lazyeval_0.2.2 curl_3.3
[19] uuid_0.1-2 data.table_1.12.0 rstudioapi_0.10 callr_3.2.0 labeling_0.3 desc_1.2.0
[25] devtools_2.0.1 munsell_0.5.0 compiler_3.5.2 xfun_0.9 systemfonts_0.1.1 pkgconfig_2.0.2
[31] base64enc_0.1-3 pkgbuild_1.0.3 rvg_0.2.2 htmltools_0.3.6 tidyselect_0.2.5 tibble_2.1.1
[37] crayon_1.3.4 withr_2.1.2 grid_3.5.2 gtable_0.3.0 magrittr_1.5 formatR_1.6
[43] scales_1.0.0 zip_2.0.3 cli_1.1.0 stringi_1.4.3 fs_1.2.7 remotes_2.0.2
[49] testthat_2.0.1 xml2_1.2.0 vctrs_0.2.0 lambda.r_1.2.3 tools_3.5.2 glue_1.3.1
[55] purrr_0.3.2 processx_3.3.0 pkgload_1.0.2 yaml_2.2.0 colorspace_1.4-1 sessioninfo_1.1.1
[61] memoise_1.1.0 usethis_1.4.0
AWS lambda session info:
R version 3.5.2 (2018-12-20)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Amazon Linux AMI 2018.03
Matrix products: default BLAS: /opt/R/lib/libRblas.so LAPACK: /opt/R/lib/libRlapack.so
locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
[3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8
[5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8
[7] LC_PAPER=en_US.UTF-8 LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] flextable_0.5.6 knitr_1.26 officedown_0.0.5.002
[4] officer_0.3.6 rmarkdown_2.0 aws.s3_0.3.12
[7] ggplot2_3.2.1 stringr_1.4.0 tidyr_1.0.0
[10] dplyr_0.8.3 hms_0.5.2 lubridate_1.7.4
[13] config_0.3 futile.logger_1.4.3 jsonlite_1.6
[16] httr_1.4.1
loaded via a namespace (and not attached): [1] tidyselect_0.2.5 xfun_0.11 purrr_0.3.3
[4] colorspace_1.4-1 vctrs_0.2.0 htmltools_0.4.0
[7] yaml_2.2.0 base64enc_0.1-3 rlang_0.4.2
[10] pillar_1.4.2 glue_1.3.1 withr_2.1.2
[13] gdtools_0.2.1 lambda.r_1.2.4 uuid_0.1-2
[16] lifecycle_0.1.0 munsell_0.5.0 gtable_0.3.0
[19] zip_2.0.4 evaluate_0.14 memoise_1.1.0
[22] curl_4.3 Rcpp_1.0.3 scales_1.1.0
[25] backports_1.1.5 formatR_1.7 systemfonts_0.1.1
[28] digest_0.6.23 stringi_1.4.3 grid_3.5.2
[31] tools_3.5.2 magrittr_1.5 lazyeval_0.2.2
[34] tibble_2.1.3 futile.options_1.0.1 crayon_1.3.4
[37] aws.signature_0.5.2 pkgconfig_2.0.3 zeallot_0.1.0
[40] ellipsis_0.3.0 data.table_1.12.8 xml2_1.2.2
[43] rvg_0.2.2 assertthat_0.2.1 R6_2.4.1
[46] compiler_3.5.2
Hi,
Great package. I was wondering if there is some sort of integration with Rticles or a quick way to use docx template for scientific journals?
Suppose I have a .Rmd file like below:
---
title: "Untitled"
output:
officedown::rdocx_document:
default
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
# Chapter1 {#ch1}
# Chapter2 {#ch2}
Refer to \@ref(ch1).
When \@ref(ch1) is surrounded by multibyte strings (e.g., Chinese characters), it would possibly encounter errors.
Pure multibyte + ref
上下\@ref(ch1)
Mixed multibyte/singlebyte + ref
上a下\@ref(ch1)
ref + multibyte
Example: \@ref(ch1)。
Result: compile failed
Error in nchar(u, itype) : invalid multibyte string, element 1
Calls: ... regmatches<- -> regmatches -> Map -> mapply ->
Can you please look into this issue? Thanks.
R version 4.0.2 (2020-06-22)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 20180)
Matrix products: default
locale:
[1] LC_COLLATE=Chinese (Simplified)_China.936
[2] LC_CTYPE=Chinese (Simplified)_China.936
[3] LC_MONETARY=Chinese (Simplified)_China.936
[4] LC_NUMERIC=C
[5] LC_TIME=Chinese (Simplified)_China.936
attached base packages:
[1] stats graphics grDevices utils datasets methods
[7] base
other attached packages:
[1] officer_0.3.12 officedown_0.2.0 flextable_0.5.10
[4] ggplot2_3.3.2 tidyr_1.1.1 knitr_1.29
[7] dplyr_1.0.2 reticulate_1.16
loaded via a namespace (and not attached):
[1] Rcpp_1.0.5 lattice_0.20-41 prettyunits_1.1.1
[4] sysfonts_0.8.1 ps_1.3.4 utf8_1.1.4
[7] rprojroot_1.3-2 assertthat_0.2.1 digest_0.6.25
[10] R6_2.4.1 backports_1.1.9 evaluate_0.14
[13] pillar_1.4.6 gdtools_0.2.2 rlang_0.4.7
[16] curl_4.3 uuid_0.1-4 data.table_1.13.0
[19] callr_3.4.3 Matrix_1.2-18 rmarkdown_2.3
[22] desc_1.2.0 labeling_0.3 devtools_2.3.1
[25] stringr_1.4.0 munsell_0.5.0 tinytex_0.25
[28] compiler_4.0.2 xfun_0.16 pkgconfig_2.0.3
[31] systemfonts_0.2.3 base64enc_0.1-3 pkgbuild_1.1.0
[34] rvg_0.2.5 htmltools_0.5.0 tidyselect_1.1.0
[37] tibble_3.0.3 bookdown_0.20 fansi_0.4.1
[40] crayon_1.3.4 showtextdb_3.0 withr_2.2.0
[43] grid_4.0.2 jsonlite_1.7.0 gtable_0.3.0
[46] lifecycle_0.2.0 magrittr_1.5 scales_1.1.1
[49] zip_2.1.0 cli_2.0.2 stringi_1.4.6
[52] farver_2.0.3 fs_1.5.0 remotes_2.2.0
[55] testthat_2.3.2 xml2_1.3.2 ellipsis_0.3.1
[58] generics_0.0.2 vctrs_0.3.2 tools_4.0.2
[61] showtext_0.9 glue_1.4.1 purrr_0.3.4
[64] processx_3.4.3 pkgload_1.1.0 yaml_2.2.1
[67] colorspace_1.4-1 sessioninfo_1.1.1 memoise_1.1.0
[70] usethis_1.6.1
I've been using officedown to create reports for a while, and recently started to implement flextables to create tables with proper layouts. However, the structure of my report means there is one master .Rmd, which imports subsections from a subfolder. Whenever attempting to add a flextable to one of these subsections, it attempts to search for the master markdown's reference_docx
within the subsections
folder, even though any reference to that should be run while working in the main folder. When writing other code and text and referring to variables, everything is executed in the context of the main Rmd.
The exact error:
Quitting from lines NA-7 (./subsections/subsection.Rmd) Error: could not find file 'word_templates/template.docx' Execution halted
In terms of the reproducible example:
reprex.Rmd uses reference_docx, found at word_templates/template.docx
subsection.Rmd is imported in reprex.Rmd, and all of its code is executed in the context of reprex.Rmd in the base folder. However, once it has a flextable, it attempts to look for reference_docx in subsections/word_templates/template.docx
.
This can be reproduced with the following file structure:
---
output:
officedown::rdocx_document:
reference_docx: word_templates/template.docx
---
```{r include=FALSE}
library(knitr)
library(officedown)
library(officer)
library(flextable)
```
```{r, child="subsections/subsection.Rmd"}
```
---
output: word_document
---
```{r}
table_test <- flextable(head(airquality))
table_test
```
Alongside any word file called template.docx, at the path word_templates/template.docx
.
sessionInfo():
> sessionInfo()
R version 4.0.3 (2020-10-10)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Catalina 10.15.7
Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRlapack.dylib
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
loaded via a namespace (and not attached):
[1] compiler_4.0.3 htmltools_0.5.0 tools_4.0.3 yaml_2.2.1 tinytex_0.27 rmarkdown_2.5 knitr_1.30
[8] digest_0.6.27 xfun_0.19 rlang_0.4.9 evaluate_0.14
Note: I'm not entirely sure whether this belongs in the issues of flextable
, officer
, or officedown
. If you want me to repost it in another repository, please let me know.
Thanks for your great work. Is there a way to have page breaks in landscape sections? This does not seem to work:
<!---BLOCK_LANDSCAPE_START--->
<!---CHUNK_PAGEBREAK--->
<!---BLOCK_LANDSCAPE_STOP--->
Saw Issue 26 and I got interested in creating templates for journals. I have always avoided knitting to docx until I found officedown
, its been good to me and I would like to return the favour in some way.
I would be willing to start contributing templates as I submit my articles to journals. I think one way I could help is by showing how to make a template. But I will be honest some of the editing is above my head. I uploaded a YouTube video below with my attempt. @davidgohel if you're willing to comment. I can remake a better video so people can see how to make their own docx template. There really is not much out there showcasing the best way to do this. The example in the zip file is for the Journal of Biomedical Optics and Neurophotonics
Within the Rmd file you'll see some of my workarounds which involves calling ::: {custom-style="Author Names"}
which is most definitely not as elegant a solution as you will find in other packages such as papaja
where these arguments would be incorporated into yaml
.
`
Let me know if you think this is a viable endeavour.
The code I used for the RMarkdown is here and I also uploaded the project directory.
Hi
Thanks for your work. I will be able to get closer to my goal!
After trial and errors (and reading this, I finally was able to insert docx in my document, but with this syntax
<!---BLOCK_POUR_DOCX{docx_file: 'test.docx'}--->
instead of mentioned snippet in your doc
<!---BLOCK_POUR_DOCX{docx_file:'path/to/docx'}--->
Small detail but useful for beginner to know.
Thanks
Mel
Although the manual of officedown
states that 'rpptx_document2
also supports cross reference based on the syntax of the bookdown package', actually there is no function called rpptx_document2
and this halts the knitting a pptx document with an error: Error: 'rpptx_document2' is not an exported object from 'namespace:officedown'
. Due to this problem, it is impossible to cross-refer a figure/table number.
---
title: "Week 8"
author: "CLRR"
output:
officedown::rpptx_document2:
keep_md: TRUE
---
## test
Description
sessionInfo()
.R version 4.0.2 (2020-06-22)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 18363)
Matrix products: default
locale:
[1] LC_COLLATE=Japanese_Japan.932 LC_CTYPE=Japanese_Japan.932 LC_MONETARY=Japanese_Japan.932 LC_NUMERIC=C LC_TIME=Japanese_Japan.932
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] viridis_0.5.1 viridisLite_0.3.0 magrittr_1.5 forcats_0.5.0 stringr_1.4.0 dplyr_1.0.2 purrr_0.3.4 readr_1.4.0 tidyr_1.1.2
[10] tibble_3.0.4 ggplot2_3.3.2 tidyverse_1.3.0
loaded via a namespace (and not attached):
[1] tidyselect_1.1.0 xfun_0.19 haven_2.3.1 colorspace_1.4-1 vctrs_0.3.4 generics_0.1.0 htmltools_0.5.0 yaml_2.2.1
[9] rlang_0.4.8 pillar_1.4.6 withr_2.3.0 glue_1.4.2 DBI_1.1.0 gdtools_0.2.2 dbplyr_2.0.0 modelr_0.1.8
[17] readxl_1.3.1 uuid_0.1-4 lifecycle_0.2.0 munsell_0.5.0 gtable_0.3.0 cellranger_1.1.0 rvest_0.3.6 zip_2.1.1
[25] memoise_1.1.0 evaluate_0.14 labeling_0.4.2 knitr_1.30 fansi_0.4.1 broom_0.7.2 Rcpp_1.0.5 backports_1.2.0
[33] scales_1.1.1 jsonlite_1.7.1 farver_2.0.3 systemfonts_0.3.2 fs_1.5.0 gridExtra_2.3 hms_0.5.3 digest_0.6.27
[41] stringi_1.5.3 officedown_0.2.0.002 grid_4.0.2 cli_2.1.0 tools_4.0.2 crayon_1.3.4 pkgconfig_2.0.3 ellipsis_0.3.1
[49] xml2_1.3.2 rvg_0.2.5 reprex_0.3.0 lubridate_1.7.9 assertthat_0.2.1 rmarkdown_2.5 officer_0.3.15 httr_1.4.2
[57] rstudioapi_0.11 R6_2.5.0 compiler_4.0.2
The version of Pandoc available in my environment is good enough to produce the pptx output.
rmarkdown::pandoc_version()
[1] ‘2.10.1’
packageVersion("officedown")
[1] ‘0.2.0.2’
I hope this package can support tables of regression results built by packages like stargazer.
Hi there. I have tried to use the Pandoc custom styles. Unfortunately, the bracketed_spans syntax (https://pandoc.org/MANUAL.html#custom-styles) DOES NOT work for me in my Rmarkdown scripts. The fenced_divs syntax DOES work in some cases, not all. It would be great if you could bring back functions such as the "chunk_styled_text" to the Officedown R package. Thanks in advance.
Alex Hernandez
As discussed last week, the following branch will contain improvements
https://github.com/davidgohel/officedown/tree/newfeatures
Some progress have been made and can be tested. An example is available here:
https://github.com/davidgohel/officedown/tree/newfeatures/inst/example
The expected result is the following file:
example.docx
I will go on this week and next week. Let me know if any question
Hi David,
I've got a reference document that has a page header and footer but I would like to change them for the report I create with officedown. So for each report they should take on the title of the officedown document.
I found the headers_replace_all_text() function of officer and could create my word document using Rmd and officedown and in a second pass run the officer::headers_replace_all_text() function to change the header.
But I was wondering if there's a quicker way to do this in the Rmd file itself? (I can't see a way to get the headers_replace function to work from within the Rmd file)
When generating lists of tables and figures, figure and table numbers appear inconsistently or not at all. In the demo, I have substituted the original TOC code with:
<!---BLOCK_TOC{style: 'Image Caption', separator: ','}--->
<!---BLOCK_TOC{style: 'Table Caption', separator: ','}--->
I didn't change the demo code in any other way. In my own tests, I can't get figure and table numbers to appear in the lists at all. Hyperlinks in the text display as expected (e.g. using \@ref(fig:ts-plot)
.)
Notice that some figure and table numbers appear and others do not.
Thank you for this awesome package, a lot of the new features are real game changers for me!
Is it possible to use the styling options provided by officer::ftext
within the figure caption (fig.cap) of a code chunk?
My unsuccessful attempt was to first create a caption object:
test_caption <- officer::fpar(officer::ftext("hello", officer::shortcuts$fp_bold()))
which I then tried referencing in a chunk like this:
r, echo=FALSE, fig.cap=test_caption, fig.id='sinus', fig.width=6, fig.height=4, fig.align='center'
I know that you have added Math latex support to captions, but I would love combining, for example, two colors within one figure caption. At the moment, I am only aware of Claus Wilke's ggtext
package for multi-colored captions - which have to be included as part of the figure. However, I would prefer a way of combining Word's image captions (for the numbering and so on) with officer
's advanced formatting options (that exceed changing the "Image Caption" style in the reference.docx).
It seems when using "-" (and maybe other special characters) as table/figure ids, referencing them is not possible anymore using the \@ref(id-dash)
syntax.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.