# NOT RUN {
library(rmarkdown)
# official template -----
skeleton <- system.file(package = "officedown",
"rmarkdown/templates/word/skeleton/skeleton.Rmd")
rmd_file <- tempfile(fileext = ".Rmd")
file.copy(skeleton, to = rmd_file)
docx_file_1 <- tempfile(fileext = ".docx")
render(rmd_file, output_file = docx_file_1, quiet = TRUE)
# bookdown example -----
# All above is only to make sure we do not write in your wd
bookdown_loc <- system.file(package = "officedown", "examples/bookdown")
temp_dir <- tempfile()
dir.create(temp_dir, showWarnings = FALSE, recursive = TRUE)
file.copy(
from = list.files(bookdown_loc, full.names = TRUE),
to = temp_dir,
overwrite = TRUE, recursive = TRUE)
render_site(
input = temp_dir, encoding = 'UTF-8',
envir = new.env(), quiet = TRUE)
docx_file_2 <- file.path(temp_dir, "_book", "bookdown.docx")
if(file.exists(docx_file_2)){
message("file ", docx_file_2, " has been written.")
}
# }
Run the code above in your browser using DataLab