davidgohel / ReporteRs

Note that ReporteRs has been removed from CRAN the 16th of July 2018 and is not maintained anymore. please migrate to officer.
244 stars 44 forks source link

Template styles overwritten by ReporteRs default font #150

Closed slarge closed 8 years ago

slarge commented 8 years ago

Some unexpected behaviour has just turned up while modifying a template with bookmarks. Given the template, the stylenames "EcoregionHeader" and "AdviceHeading" should both be in Calibri and font sized 9 and 11. The output document "tester.docx", however, remains in the default font and font size. Your thoughts are appreciated.

  rm(list = ls())
  library(ReporteRs)
  library(magrittr)
  draftDoc <- docx(template = "~/AdviceTemplate.docx")

  # styles(draftDoc)
  draftDoc <- draftDoc %>%
    addParagraph(value = "TEXT text text text",
                 stylename = "EcoregionHeader",
                 bookmark = "Ecoregion_Header") %>%
    addParagraph(value = "Other text text text",
                 stylename = "AdviceHeading",
                 bookmark = "Advice_Heading")

  writeDoc(draftDoc, file = paste0("~/tester.docx"))
  getOption("ReporteRs-default-font")
  sessionInfo()

[1] "Times New Roman"

sessionInfo() R version 3.3.2 (2016-10-31) Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows >= 8 x64 (build 9200)

locale: [1] LC_COLLATE=English_United Kingdom.1252 LC_CTYPE=English_United Kingdom.1252 LC_MONETARY=English_United Kingdom.1252 [4] LC_NUMERIC=C LC_TIME=English_United Kingdom.1252

attached base packages: [1] stats graphics grDevices utils datasets methods base

other attached packages: [1] magrittr_1.5 ReporteRs_0.8.7 ReporteRsjars_0.0.2 rJava_0.9-8

loaded via a namespace (and not attached): [1] Rcpp_0.12.7 png_0.1-7 withr_1.0.2 digest_0.6.10 mime_0.5 R.methodsS3_1.7.1 R6_2.1.2
[8] xtable_1.8-2 gdtools_0.1.3 R.oo_1.20.0 R.utils_2.5.0 xml2_1.0.0 devtools_1.12.0 tools_3.3.2
[15] shiny_0.14.2 httpuv_1.3.3 memoise_1.0.0 htmltools_0.3.5 rvg_0.1.1 knitr_1.15

AdviceTemplate.docx tester.docx

davidgohel commented 8 years ago

Should be fixed now. Reopen issue if not.

David

slarge commented 8 years ago

Thanks David, This solved the issue at hand, but now I am having unexpected behaviour with \n and \t. I am expecting two tabs in the first bookmark replacement and two full lines in the second replacement.

rm(list = ls())
  library(ReporteRs)
  library(magrittr)
  draftDoc <- docx(template = "~/AdviceTemplate.docx")

  # styles(draftDoc)
  draftDoc <- draftDoc %>%
    addParagraph(value = "TEXT text \t\t text text",
                 stylename = "EcoregionHeader",
                 bookmark = "Ecoregion_Header") %>%
    addParagraph(value = "Other text \n\n text text",
                 stylename = "AdviceHeading",
                 bookmark = "Advice_Heading")

  writeDoc(draftDoc, file = paste0("~/tester.docx"))
  getOption("ReporteRs-default-font")
  sessionInfo()

sessionInfo()

R version 3.3.2 (2016-10-31) Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows >= 8 x64 (build 9200)

locale: [1] LC_COLLATE=English_United Kingdom.1252 LC_CTYPE=English_United Kingdom.1252 LC_MONETARY=English_United Kingdom.1252 [4] LC_NUMERIC=C LC_TIME=English_United Kingdom.1252

attached base packages: [1] stats graphics grDevices utils datasets methods base

other attached packages: [1] tidyr_0.6.0 dplyr_0.5.0 icesSAG_1.1-0 icesSLD_0.0-0 ReporteRs_0.8.7.9003 ReporteRsjars_0.0.2 devtools_1.12.0

loaded via a namespace (and not attached): [1] Rcpp_0.12.7 magrittr_1.5 knitr_1.15 xml2_1.0.0 xtable_1.8-2 R6_2.1.2 httr_1.2.1 tools_3.3.2
[9] grid_3.3.2 rvg_0.1.1 R.oo_1.20.0 png_0.1-7 DBI_0.4-1 git2r_0.15.0 withr_1.0.2 htmltools_0.3.5
[17] lazyeval_0.2.0 assertthat_0.1 digest_0.6.10 tibble_1.2 rJava_0.9-8 shiny_0.14.2 bitops_1.0-6 R.utils_2.5.0
[25] RCurl_1.95-4.8 curl_2.2 memoise_1.0.0 mime_0.5 gdtools_0.1.3 R.methodsS3_1.7.1 XML_3.98-1.4 jsonlite_1.1
[33] httpuv_1.3.3

AdviceTemplate.docx tester.docx