# NOT RUN {
library(rmarkdown)
run_ok <- pandoc_available() &&
pandoc_version() >= numeric_version("2.0")
if(run_ok){
# minimal example -----
example <- system.file(package = "officedown",
"examples/minimal_word.Rmd")
rmd_file <- tempfile(fileext = ".Rmd")
file.copy(example, to = rmd_file)
docx_file_1 <- tempfile(fileext = ".docx")
render(rmd_file, output_file = docx_file_1, quiet = TRUE)
render(rmd_file, output_file = docx_file_1, quiet = TRUE,
intermediates_dir = tempfile())
# bookdown example -----
if(require("bookdown")){
bookdown_loc <- system.file(package = "officedown", "examples/bookdown")
temp_dir <- tempfile()
# uncomment next line to get the result in your working directory
# temp_dir <- "./bd_example"
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