read and import a docx file as an R object representing the document.

read_docx(path = NULL)

# S3 method for rdocx
print(x, target = NULL, ...)

# S3 method for rdocx
length(x)

Arguments

path

path to the docx file to use as base document.

x

an rdocx object

target

path to the docx file to write

...

unused

Examples

# create an rdocx object with default template --- read_docx()
#> rdocx document with 2 element(s) #> #> * styles: #> Normal heading 1 heading 2 #> "paragraph" "paragraph" "paragraph" #> heading 3 Default Paragraph Font Normal Table #> "paragraph" "character" "table" #> No List strong centered #> "numbering" "character" "paragraph" #> table_template Light List Accent 2 Titre 1 Car #> "table" "table" "character" #> Titre 2 Car Titre 3 Car graphic title #> "character" "character" "paragraph" #> table title Table Professional toc 1 #> "paragraph" "table" "paragraph" #> toc 2 Balloon Text Texte de bulles Car #> "paragraph" "paragraph" "character" #> #> * Content at cursor location: #> level num_id text style_name content_type #> 1 NA NA NA paragraph
print(read_docx())
#> rdocx document with 2 element(s) #> #> * styles: #> Normal heading 1 heading 2 #> "paragraph" "paragraph" "paragraph" #> heading 3 Default Paragraph Font Normal Table #> "paragraph" "character" "table" #> No List strong centered #> "numbering" "character" "paragraph" #> table_template Light List Accent 2 Titre 1 Car #> "table" "table" "character" #> Titre 2 Car Titre 3 Car graphic title #> "character" "character" "paragraph" #> table title Table Professional toc 1 #> "paragraph" "table" "paragraph" #> toc 2 Balloon Text Texte de bulles Car #> "paragraph" "paragraph" "character" #> #> * Content at cursor location: #> level num_id text style_name content_type #> 1 NA NA NA paragraph
# write a rdocx object in a docx file ---- if( require(magrittr) ){ read_docx() %>% print(target = "out.docx") # full path of produced file is returned print(.Last.value) }
#> [1] "officer" "ggplot2" "stringr" "purrr" "magrittr" "testthat" #> [7] "stats" "graphics" "grDevices" "utils" "datasets" "methods" #> [13] "base"
# how many elements are there in the document ---- length( read_docx() )
#> [1] 2