title | output |
---|---|
Officer and Flextable |
html_document |
knitr::opts_chunk$set(echo = TRUE)
- RStudio
- Java enabled operating systems (e.g. REMSOFTSVR03)
Key R packages for Creating Documents
- Officer
- FlexTable
library(officer)
library(flextable)
-
A Template document can be accessed by using the
read_docx()
command, specifying the location and name of the template document. -
Remark: for ease of use, the master template document can be divided up into component parts, which would make the insertion of tables into the document easier.
-
For this first step, it is advisable to use the first component of the master termplate (corresponding to the first set of pages.)
myDoc <- read_docx("myTemplate_Part_A.docx")
- Designated Keywords in the template can be replaced with amended values (e.g. specific location names, file references, activity types)
- Designated Keywords MUST NOT include square brackets, as the programme will parse them as regular expressions.
myDoc <- myDoc %>% body_replace_all_text("THISSITENAME",mySiteName[i] , only_at_cursor = FALSE)
myDoc <- myDoc %>% body_replace_all_text("THISFILEREF",myFLRef[i] , only_at_cursor = FALSE)
- Text may be added to the document, but it would be unformatted. This would affect the visual appeal of the output.
- For best use, the text should be preformatted with specified settings.
- The commands are
fpar()
andftext()
. - Formatting may be predefined.
bold_face_1 <- shortcuts$fp_bold(font.size = 24)
bold_face_2 <- shortcuts$fp_bold(font.size = 20)
bold_face_3 <- shortcuts$fp_bold(font.size = 16)
bold_redface <- update(bold_face_1, color = "red")
The following example shows how to create and format text for a paragraph.
code> fpar_title <- fpar(ftext("Appropriate Assessment Screening", prop = bold_face_1)) AA_Text_1 <- "The project has been subject to the DAFM's AA Screening procedure, as set out in the document entitled Appropriate Assessment Procedure: Guidance Note & iFORIS SOP for DAFM Forestry Inspectors (v.05Nov19) (DAFM, 2019). The AA Screening report is included on file for this application." AA_Text_2 <- "The AA Screening procedure identified all European sites within 15 km of the project area. The potential for an effect on European sites located outside the 15 km was also considered, but no pathways for significant effect were identified. " AA_Text_3 <- "This process concluded that there was no possibility of the project - either individually or in combination with other plans and projects - having an effect on the following Natura site(s): " fpar_1 <- fpar(ftext(AA_Text_1, prop = fp_text(color = "black", font.size = 10, bold = FALSE))) fpar_2 <- fpar(ftext(AA_Text_2, prop = fp_text(color = "black", font.size = 10, bold = FALSE))) fpar_3 <- fpar(ftext(AA_Text_3, prop = fp_text(color = "black", font.size = 10, bold = FALSE)))
Now that the text is created and formatted, It can be added to the main document.
myDoc <- myDoc %>%
body_add_fpar(fpar_title) %>%
body_add_par("", style = "Normal") %>%
body_add_fpar(fpar_1) %>%
body_add_par("", style = "Normal") %>%
body_add_fpar(fpar_2) %>%
body_add_par("", style = "Normal") %>%
body_add_fpar(fpar_3) %>%
body_add_par("", style = "Normal")