diff --git a/R/html_all_figs_tables.R b/R/html_all_figs_tables.R deleted file mode 100644 index 1d0f13e5..00000000 --- a/R/html_all_figs_tables.R +++ /dev/null @@ -1,121 +0,0 @@ -#' #' Make an html file with all figures and tables -#' #' -#' #' Show all tables and figures in a single html file. -#' #' -#' #' @param figures_tables_dir Path. The location of the folder containing -#' #' figures and tables ("figures" and "tables"). -#' #' -#' #' Default: The current working directory (`getwd()`) -#' #' -#' #' @returns A folder ("all_tables_figures") in your working directory containing -#' #' html and qmd files that show all tables and figures. -#' #' -#' #' @seealso -#' #' \code{\link[asar:create_figures_doc]{asar::create_figures_doc()}}, -#' #' \code{\link[asar:create_tables_doc]{asar::create_tables_doc()}} -#' #' -#' #' -#' #' -#' #' @examples -#' #' \dontrun{ -#' #' html_all_figs_tables() -#' #' html_all_figs_tables(figures_tables_dir = "my_figures_tables_dir") -#' #' } -#' html_all_figs_tables <- function(figures_tables_dir = getwd()) { -#' if (!dir.exists(fs::path(figures_tables_dir, "figures"))) { -#' cli::cli_alert_danger("'figures' folder not found.") -#' cli::cli_alert_warning("Figures will not be included in the html.") -#' cli::cli_alert_info("Did you enter the correct argument for figures_tables_dir?") -#' cli::cli_alert_info("figures_tables_dir entered as {figures_tables_dir}") -#' } -#' -#' if (!dir.exists(fs::path(figures_tables_dir, "tables"))) { -#' cli::cli_alert_danger("'tables' folder not found.") -#' cli::cli_alert_warning("Tables will not be included in the html.") -#' cli::cli_alert_info("Did you enter the correct argument for figures_tables_dir?") -#' cli::cli_alert_info("figures_tables_dir entered as {figures_tables_dir}") -#' } -#' -#' # check if dir exists and present warning message/option message -#' if (dir.exists(fs::path(figures_tables_dir, "all_tables_figures"))) { -#' question1 <- readline( -#' "The 'all_tables_figures' folder already exists within your working directory. Would you like to overwrite the files within this folder? (Y/N)" -#' ) -#' } else { -#' # indicate to proceed with function -#' question1 <- "y" -#' } -#' -#' if (regexpr(question1, "y", ignore.case = TRUE) == 1) { -#' # create new folder for the html and qmd files -#' doc_path <- fs::path(figures_tables_dir, "all_tables_figures") -#' dir.create(doc_path) -#' -#' asar::create_tables_doc( -#' subdir = figures_tables_dir, -#' tables_dir = figures_tables_dir -#' ) -#' -#' asar::create_figures_doc( -#' subdir = figures_tables_dir, -#' figures_dir = figures_tables_dir -#' ) -#' -#' tab_doc_name <- list.files(figures_tables_dir)[grepl("_tables.qmd", list.files(figures_tables_dir))] -#' tab_doc <- readLines(fs::path(figures_tables_dir, tab_doc_name)) -#' -#' fig_doc_name <- list.files(figures_tables_dir)[grepl("_figures.qmd", list.files(figures_tables_dir))] -#' fig_doc <- readLines(fs::path(figures_tables_dir, fig_doc_name)) -#' -#' tabs_figs_text <- c( -#' tab_doc, -#' fig_doc -#' ) -#' -#' yaml_text <- -#' "--- -#' title: 'All Tables & Figures' -#' format: -#' html: -#' toc: true -#' embed-resources: true -#' --- -#' " -#' -#' new_html_qmd <- c(yaml_text, tabs_figs_text) -#' -#' writeLines( -#' new_html_qmd, -#' fs::path(figures_tables_dir, "all_tables_figures.qmd") -#' ) -#' -#' withr::with_dir( -#' figures_tables_dir, -#' quarto::quarto_render( -#' input = fs::path(figures_tables_dir, "all_tables_figures.qmd"), -#' output_file = fs::path("all_tables_figures.html") -#' ) -#' ) -#' -#' file.rename( -#' from = fs::path(figures_tables_dir, "all_tables_figures.html"), -#' to = fs::path( -#' doc_path, -#' "all_tables_figures.html" -#' ) -#' ) -#' -#' file.rename( -#' from = fs::path(figures_tables_dir, "all_tables_figures.qmd"), -#' to = fs::path( -#' doc_path, -#' "all_tables_figures.qmd" -#' ) -#' ) -#' -#' cli::cli_alert_success("Generated html and qmd with all tables and figures", wrap = TRUE) -#' cli::cli_alert_info("Overwrote previous html and qmd") -#' } else { -#' cli::cli_alert_warning("Did not generate html and qmd with all tables and figures", wrap = TRUE) -#' } -#' } diff --git a/tests/testthat/test-html_all_figs_tables.R b/tests/testthat/test-html_all_figs_tables.R deleted file mode 100644 index f1d0867d..00000000 --- a/tests/testthat/test-html_all_figs_tables.R +++ /dev/null @@ -1,93 +0,0 @@ -# # Dependent on save_all_plots -- uncomment when that fxn is fixed -# test_that("html_all_figs_tables makes qmd and html files with default figures_tables_dir argument", { -# save_all_plots( -# stockplotr::example_data, -# recruitment_unit_label = "mt", -# recruitment_scale_amount = 1, -# ref_line = c("unfished" = 1000), -# ref_line_sb = "msy", -# index_unit_label = "CPUE", -# figures_tables_dir = getwd() -# ) |> -# suppressWarnings() - - -# html_all_figs_tables() - -# testthat::expect(file.exists(fs::path(getwd(), "all_tables_figures", "all_tables_figures.qmd")), -# failure_message = "Test fail: 'all_tables_figures.qmd' does not exist" -# ) -# testthat::expect(file.exists(fs::path(getwd(), "all_tables_figures", "all_tables_figures.html")), -# failure_message = "Test fail: 'all_tables_figures.html' does not exist" -# ) - -# # erase temporary testing files -# unlink(fs::path(getwd(), "all_tables_figures"), recursive = T) -# file.remove(fs::path(getwd(), "captions_alt_text.csv")) -# file.remove(fs::path(getwd(), "key_quantities.csv")) -# file.remove(fs::path(getwd(), "08_tables.qmd")) -# file.remove(fs::path(getwd(), "09_figures.qmd")) -# unlink(fs::path(getwd(), "figures"), recursive = T) -# unlink(fs::path(getwd(), "tables"), recursive = T) -# }) -# -# test_that("html_all_figs_tables makes qmd and html files with non-default figures_tables_dir argument", { -# rda_path <- fs::path(getwd(), "data") -# dir.create(rda_path) - -# withr::with_dir( -# rda_path, -# save_all_plots( -# stockplotr::example_data, -# recruitment_unit_label = "mt", -# recruitment_scale_amount = 1, -# ref_line = c("unfished"=1000), -# ref_line_sb = "msy", -# index_unit_label = "CPUE", -# figures_tables_dir = getwd() -# ) |> -# suppressWarnings() -# ) - -# html_all_figs_tables(figures_tables_dir = rda_path) - -# testthat::expect(file.exists(fs::path(rda_path, "all_tables_figures", "all_tables_figures.qmd")), -# failure_message = "Test fail: 'all_tables_figures.qmd' does not exist" -# ) -# testthat::expect(file.exists(fs::path(rda_path, "all_tables_figures", "all_tables_figures.html")), -# failure_message = "Test fail: 'all_tables_figures.html' does not exist" -# ) - -# # erase temporary testing files -# # unlink(fs::path(getwd(), "all_tables_figures"), recursive = T) -# # unlink(fs::path(getwd(), "figures_tables"), recursive = T) -# unlink(fs::path(getwd(), "data"), recursive = T) -# }) -# -# test_that("html_all_figs_tables triggers message (question) when all_tables_figures folder already present", { -# save_all_plots( -# stockplotr::example_data, -# end_year = 2024, -# recruitment_unit_label = "mt", -# recruitment_scale_amount = 1, -# ref_line = "unfished", -# ref_point = 1000, -# ref_line_sb = "msy", -# index_unit_label = "CPUE", -# figures_tables_dir = getwd() -# ) |> -# suppressWarnings() - -# dir.create(fs::path(getwd(), "all_tables_figures")) - -# testthat::expect_warning(html_all_figs_tables()) - -# # erase temporary testing files -# unlink(fs::path(getwd(), "all_tables_figures"), recursive = T) -# file.remove(fs::path(getwd(), "captions_alt_text.csv")) -# file.remove(fs::path(getwd(), "key_quantities.csv")) -# file.remove(fs::path(getwd(), "08_tables.qmd")) -# file.remove(fs::path(getwd(), "09_figures.qmd")) -# unlink(fs::path(getwd(), "figures"), recursive = T) -# unlink(fs::path(getwd(), "tables"), recursive = T) -# })