#' Add MAKE ALL script
#'
#' Adds 99_make_clean.R to R/, and defines files
#' to be autogenerated. Currently defaults running
#' all prefix-numbered files up to 89 (files in the
#' 90's are assumed to be infrastructure, not analyses).
#'
#' @return adds 99_make_all.R to R/ if this doesn't
#' already exist.
#' @import here
#' @export
add_make_all <- function(){
if(file.exists(here::here("R", "99_make_all.R"))){
cat("R/99_make_all.R already exists!\n")
}else{
file.create(here::here("R", "99_make_all.R"))
files_in_r <- dir(here::here("R"))
numbered_files <-
files_in_r[grep("^[[:digit:]]{2}_", files_in_r)]
files_in_r_to_run <-
numbered_files[grep("[0-8]",
substr(numbered_files, 1, 1))]
file_string <- "files_in_r_to_run <- \n c("
if(length(files_in_r_to_run) > 0){
for(i1 in 1:length(files_in_r_to_run)){
file_string <-
paste0(file_string, "\"",
files_in_r_to_run[i1], "\"")
if(i1 < length(files_in_r_to_run)){
file_string <- paste0(file_string, ",\n ")
}
}
}
file_string <- paste0(file_string, ")")
writeLines(
c("library(here)",
"library(rmarkdown)",
"",
"if(!dir.exists(here::here(\"results\"))){",
" dir.create(here::here(\"results\"))",
"}",
"",
file_string,
"",
"if(length(files_in_r_to_run) > 0){",
"",
" for(i1 in 1:length(files_in_r_to_run)){",
" rmarkdown::render(here::here(\"R\", files_in_r_to_run[i1]),",
" output_format =",
" github_document(html_preview = TRUE,",
" toc = TRUE),",
" output_dir = here::here(\"results\"))",
"",
" }",
"}",
"",
"if(file.exists(here::here(\"README.Rmd\"))){",
" rmarkdown::render(here::here(\"README.Rmd\"),",
" output_format =",
" github_document(html_preview = TRUE,",
" toc = TRUE),",
" output_dir = here::here())",
"}"),
con = here::here("R", "99_make_all.R")
)
}
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.