Skip to content

Commit

Permalink
code to precompile vignettes
Browse files Browse the repository at this point in the history
  • Loading branch information
dramanica committed Nov 10, 2023
1 parent bb1a9bc commit eedce30
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ ci_dependencies
^codecov.yml
^data-raw$
.covrignore
^doc$
^Meta$
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@
.Ruserdata
inst/doc
docs
/doc/
/Meta/
42 changes: 42 additions & 0 deletions vignettes/precompile.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
vignette_names <- c("a0_tidysdm_overview", "a1_palaeodata_application",
"a2_tidymodels_additions","a3_troubleshooting")

if (any(!file.exists(paste0("vignettes/",vignette_names,".Rmd.orig")))){
file.rename(from = paste0("vignettes/",vignette_names,".Rmd"),
to = paste0("vignettes/",vignette_names,".Rmd.orig"))
}

for (this_vignette_prefix in vignette_names){
this_vignette <- paste0(this_vignette_prefix,".Rmd")
# Pre-compile vignette
knitr::knit(paste0("vignettes/",this_vignette,".orig"),paste0("vignettes/",this_vignette))

# remove file path such that vignettes will build with figures
replace <- readLines(paste0("vignettes/",this_vignette))
replace <- gsub("!\\[([^]]+)\\]", "![]", replace)
replace <- gsub("](figure/", paste0("](figure_",this_vignette_prefix,"/"),
replace, fixed=TRUE)
fileConn <- file(paste0("vignettes/",this_vignette))
writeLines(replace, fileConn)
close(fileConn)

if (!dir.exists(paste0("vignettes/figure_",this_vignette_prefix))){
dir.create(paste0("vignettes/figure_",this_vignette_prefix))
}
# move resource figures to vignette
resources <-
list.files("figure/", pattern = ".png$", full.names = TRUE)
file.copy(from = resources,
to = paste0("vignettes/figure_",this_vignette_prefix),
overwrite = TRUE)
# delete the figure directory
unlink("figure/",recursive = TRUE)
}




#library("devtools")
#build_vignettes()


0 comments on commit eedce30

Please sign in to comment.