Skip to content

Commit

Permalink
Reorder skeleton (#59)
Browse files Browse the repository at this point in the history
* update(template): add changes for debugging and issue

- Added options for english and removed the old czech lang the in-header doc
- changed the chunks for figs and tabs not to render while development is occurring

* update(template): add changes for debugging and issue

- Added options for english and removed the old czech lang the in-header doc
- changed the chunks for figs and tabs not to render while development is occurring

* Attempt to inherit custom_sections parameter from asar::create_template()

* Changed remaining x's (former argument) into custom_sections (new argument), and removed the parameter definition

* Clarified argument definitions for create_title.R

* Clarified argument definitions in create_template. Since associated scripts (add_section, create_title, format_quarto) used same parameters (but with different names), changed the parameter names in associated scripts to names in create_template, then inherited parameter names from create_template to reduce redundancy.

Questions for Sam:
Please check/edit the "parameters" parameter's definition. What does it mean, and how should it be defined? Is it ever false?

Please check/edit the "param_values" parameter's definition. What does it mean, and how should it be defined?

Please check/edit the "convert_output" parameter's definition for accuracy.

* Clarified argument definitions in convert_output.R and updated documentation.

* update(create_figures_doc): add example of where caption will go

Integration of the other captions once written and alt. text will form adjustments to here

* refactor: Changed names of sections in create_template to those voted on by steering committee (as of Sept 2024)

* deleted files with outdated names (i.e., without numbers before descriptions

* updated test-create_template.R to avoid merge conflict

* Remove test folder pushed to repo

* fix(custom section op): change base_section, add_section, and test

- changes in both naming of arguments and templates were fixed
- test-add_section was adjusted so expected values were correct

* fix(assessment spelling): change file name and will now pass test

* delete(assessment_gloassaries.tex)

* fix(test-add_section): spelling error in test

* deleted files with outdated names (i.e., without numbers before descriptions

* updated test-create_template.R to avoid merge conflict

* Remove test folder pushed to repo

* fix(assessment spelling): change file name and will now pass test

* fix(test-add_section): change file names in test and adjust fxns to meet test expectations

* fix(test-create_template): add to resdir to remove warning in test

* delete(utils): remove add_base_section from utils

* Attempt to inherit custom_sections parameter from asar::create_template()

* Changed remaining x's (former argument) into custom_sections (new argument), and removed the parameter definition

* Clarified argument definitions for add_child.R

* Clarified argument definitions for add_chunk.R

* Clarified argument definitions for add_section.R.

Note: The text previously referenced an argument that was missing from the function ('title'). In my update, I changed it to 'sec_names'. Please verify that this was an accurate assumption.

* Clarified argument definitions for create_citation.R

* Clarified argument definitions for create_figures_doc.R

* Clarified argument definitions for create_title.R

* Clarified argument definitions for export_object.R

* Clarified argument definitions for format_quarto.R

* Clarified argument definitions in create_template. Since associated scripts (add_section, create_title, format_quarto) used same parameters (but with different names), changed the parameter names in associated scripts to names in create_template, then inherited parameter names from create_template to reduce redundancy.

Questions for Sam:
Please check/edit the "parameters" parameter's definition. What does it mean, and how should it be defined? Is it ever false?

Please check/edit the "param_values" parameter's definition. What does it mean, and how should it be defined?

Please check/edit the "convert_output" parameter's definition for accuracy.

* Updated documentation

* Clarified argument definitions in convert_output.R and updated documentation.

* Update(affiliation_info.csv): add country

* update(create_figures_doc): add example of where caption will go

Integration of the other captions once written and alt. text will form adjustments to here

* Attempt to inherit custom_sections parameter from asar::create_template()

* Changed remaining x's (former argument) into custom_sections (new argument), and removed the parameter definition

* Clarified argument definitions for create_title.R

* Clarified argument definitions in create_template. Since associated scripts (add_section, create_title, format_quarto) used same parameters (but with different names), changed the parameter names in associated scripts to names in create_template, then inherited parameter names from create_template to reduce redundancy.

Questions for Sam:
Please check/edit the "parameters" parameter's definition. What does it mean, and how should it be defined? Is it ever false?

Please check/edit the "param_values" parameter's definition. What does it mean, and how should it be defined?

Please check/edit the "convert_output" parameter's definition for accuracy.

* Clarified argument definitions in convert_output.R and updated documentation.

* refactor: Changed names of sections in create_template to those voted on by steering committee (as of Sept 2024)

* deleted files with outdated names (i.e., without numbers before descriptions

* updated test-create_template.R to avoid merge conflict

* Remove test folder pushed to repo

* fix(custom section op): change base_section, add_section, and test

- changes in both naming of arguments and templates were fixed
- test-add_section was adjusted so expected values were correct

* fix(assessment spelling): change file name and will now pass test

* delete(assessment_gloassaries.tex)

* fix(test-add_section): spelling error in test

* deleted files with outdated names (i.e., without numbers before descriptions

* updated test-create_template.R to avoid merge conflict

* Remove test folder pushed to repo

* fix(assessment spelling): change file name and will now pass test

* fix(test-add_section): change file names in test and adjust fxns to meet test expectations

* fix(test-create_template): add to resdir to remove warning in test

* delete(utils): remove add_base_section from utils

* Fix naming in create_template

---------

Co-authored-by: Schiano-NOAA <[email protected]>
  • Loading branch information
sbreitbart-NOAA and Schiano-NOAA authored Oct 16, 2024
1 parent 91642c9 commit 0c49a05
Show file tree
Hide file tree
Showing 30 changed files with 311 additions and 625 deletions.
5 changes: 4 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ Imports:
gridExtra,
gt,
naniar,
nmfspalette,
officer,
openxlsx,
prodlim,
r4ss,
satf,
stats,
stringr,
Expand All @@ -40,7 +42,8 @@ VignetteBuilder:
knitr
Remotes:
nmfs-ost/satf,
r4ss/r4ss
r4ss/r4ss,
nmfs-fish-tools/nmfspalette
Config/testthat/edition: 3
Config/testthat/parallel: true
Encoding: UTF-8
Expand Down
6 changes: 3 additions & 3 deletions R/add_base_section.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ add_base_section <- function(custom_sections) {
section_list <- list()
for (i in 1:length(sec_sel)) {
sec_file <- grep(
custom_sections = list.files(system.file("templates", "skeleton", package = "asar")),
list.files(system.file("templates", "skeleton", package = "asar")),
pattern = sec_sel[i],
value = TRUE
)
if (identical(sec_file, character(0))) stop("One or more section name(s) does not exist. Please check the spelling or if you are tring to add a section that is not in the default template, please use parameter 'custom_sections' and refer to documentation. To check which sections are in the base template please run list.files(system.file('templates', 'skeleton', package = 'ASAR')) in your console")
sec_file -> section_list[i]
sec_file -> section_list[[i]]
}
section_list
as.list(unlist(section_list))
}
8 changes: 4 additions & 4 deletions R/add_section.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ add_section <- function(
# after-section
# in-section (will always append to the end of the section)
for (i in 1:length(new_section)) {
section_i_name <- paste0(gsub(" ", "_", new_section[i]), ".qmd")
section_i_name <- paste0(gsub(" ", "_", tolower(new_section[i])), ".qmd")
local_section <- forstringr::str_extract_part(section_location[i], "-", before = FALSE)
local_section_prev <- forstringr::str_extract_part(section_location[i - 1], "-", before = FALSE)

Expand All @@ -39,7 +39,7 @@ add_section <- function(
}

section_i <- paste0(
"## ", stringr::str_to_title(sub("_", " ", new_section[i])), "\n",
"## ", stringr::str_to_title(sub("_", " ", tolower(new_section[i]))), "\n",
"\n",
"[Insert text here]", "\n",
"\n",
Expand All @@ -51,9 +51,9 @@ add_section <- function(
custom_sections <- append(custom_sections, section_i_name, after = (which(grepl(local_section, custom_sections)) - 1))
} else if (locality == "after") {
if (locality %in% locality_prev & local_section %in% local_section_prev) {
custom_sections <- append(custom_sections, section_i_name, after = which(grepl(gsub(" ", "_", new_section[i - 1]), custom_sections)))
custom_sections <- append(custom_sections, section_i_name, after = which(grepl(gsub(" ", "_", tolower(new_section[i - 1])), custom_sections)))
} else {
custom_sections <- append(custom_sections, section_i_name, after = which(grepl(local_section, custom_sections)))
custom_sections <- append(custom_sections, section_i_name, after = max(which(grepl(local_section, custom_sections))))
}
} else if (locality == "in") {
stop("No available option for adding a new section 'in' another quarto document.", call. = FALSE)
Expand Down
5 changes: 3 additions & 2 deletions R/create_figures_doc.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ create_figures_doc <- function(resdir = NULL,
add_chunk(
paste0("satf::plot_recruitment(dat = '", resdir, "/", model_results, "', model = '", model, "')"),
label = "recruitment",
eval = "false",
add_option = TRUE,
chunk_op = "fig-cap: 'this is the caption for the figure.'"
),
Expand All @@ -41,13 +42,13 @@ create_figures_doc <- function(resdir = NULL,
)
figures_doc <- paste0(
figures_doc,
add_chunk(plot_code, label = "spawn_bio"),
add_chunk(plot_code, label = "spawn_bio", eval = "false"),
"\n"
)
} else {
# add option for only adding specified tables
}

# Save tables doc to template folder
utils::capture.output(cat(figures_doc), file = paste0(subdir, "/", "figures.qmd"), append = FALSE)
utils::capture.output(cat(figures_doc), file = paste0(subdir, "/", "09_figures.qmd"), append = FALSE)
}
7 changes: 5 additions & 2 deletions R/create_tables_doc.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ create_tables_doc <- function(resdir = NULL,
paste0(
"satf::table_indices(dat = '", resdir, "/", model_results, "', model = '", model, "')"
),
label = "indices"
label = "indices",
eval = "false"
)
)

Expand All @@ -44,5 +45,7 @@ create_tables_doc <- function(resdir = NULL,
}

# Save tables doc to template folder
utils::capture.output(cat(tables_doc), file = paste0(subdir, "/", "tables.qmd"), append = FALSE)
utils::capture.output(cat(tables_doc),
file = paste0(subdir, "/", "08_tables.qmd"),
append = FALSE)
}
179 changes: 99 additions & 80 deletions R/create_template.R
Original file line number Diff line number Diff line change
Expand Up @@ -276,15 +276,15 @@ create_template <- function(
"### Tables \n \n",
"Please refer to the `satf` package downloaded from remotes::install_github('nmfs-ost/satf') to add premade tables."
)
utils::capture.output(cat(tables_doc), file = fs::path(subdir, "tables.qmd"), append = FALSE)
utils::capture.output(cat(tables_doc), file = fs::path(subdir, "08_tables.qmd"), append = FALSE)
warning("Results file or model name not defined.")
}
} else {
tables_doc <- paste0(
"### Tables \n \n",
"Please refer to the `satf` package downloaded from remotes::install_github('nmfs-ost/satf') to add premade figures"
)
utils::capture.output(cat(tables_doc), file = fs::path(subdir, "tables.qmd"), append = FALSE)
utils::capture.output(cat(tables_doc), file = fs::path(subdir, "08_tables.qmd"), append = FALSE)
}
# Create figures qmd
if (include_figures) {
Expand All @@ -298,12 +298,12 @@ create_template <- function(
)
} else {
figures_doc <- paste0("## Figures \n")
utils::capture.output(cat(figures_doc), file = fs::path(subdir, "figures.qmd"), append = FALSE)
utils::capture.output(cat(figures_doc), file = fs::path(subdir, "09_figures.qmd"), append = FALSE)
warning("Results file or model name not defined.")
}
} else {
figures_doc <- paste0("## Figures \n")
utils::capture.output(cat(figures_doc), file = fs::path(subdir, "figures.qmd"), append = FALSE)
utils::capture.output(cat(figures_doc), file = fs::path(subdir, "09_figures.qmd"), append = FALSE)
}

# Part I
Expand Down Expand Up @@ -441,6 +441,7 @@ create_template <- function(
# Date
"date: today", "\n",
"lang: en \n",
"keep-tex: true \n"
)

# Add species image on title page
Expand Down Expand Up @@ -569,32 +570,38 @@ create_template <- function(
if (custom == FALSE) {
sections <- add_child(
c(
"executive_summary.qmd",
"introduction.qmd",
"data.qmd",
"modeling_approach.qmd",
"results.qmd",
"projections.qmd",
"discussion.qmd",
"acknowledgments.qmd",
"references.qmd",
"tables.qmd",
"figures.qmd",
"appendix.qmd"
"01_executive_summary.qmd",
"02_introduction.qmd",
"03_data.qmd",
"04a_assessment-configuration.qmd",
"04b_assessment-results.qmd",
"04c_assessment-sensitivity.qmd",
"04d_asessment-benchmarks.qmd",
"04e_assessment-projections.qmd",
"05_discussion.qmd",
"06_acknowledgments.qmd",
"07_references.qmd",
"08_tables.qmd",
"09_figures.qmd",
"10_notes.qmd",
"11_appendix.qmd"
),
label = c(
"executive_summary",
"introduction",
"data",
"modeling_approach",
"results",
"projections",
"discussion",
"acknowlesgements",
"references",
"tables",
"figures",
"appendix"
"01_executive_summary",
"02_introduction",
"03_data",
"04a_assessment-configuration",
"04b_assessment-results",
"04c_assessment-sensitivity",
"04d_asessment-benchmarks",
"04e_assessment-projections",
"05_discussion",
"06_acknowledgments",
"07_references",
"08_tables",
"09_figures",
"10_notes",
"11_appendix"
)
)
} else {
Expand All @@ -611,18 +618,21 @@ create_template <- function(

if (is.null(custom_sections)) {
sec_list1 <- list(
"executive_summary.qmd",
"introduction.qmd",
"data.qmd",
"modeling_approach.qmd",
"results.qmd",
"projections.qmd",
"discussion.qmd",
"acknowledgments.qmd",
"references.qmd",
"tables.qmd",
"figures.qmd",
"appendix.qmd"
"01_executive_summary.qmd",
"02_introduction.qmd",
"03_data.qmd",
"04a_assessment-configuration.qmd",
"04b_assessment-results.qmd",
"04c_assessment-sensitivity.qmd",
"04d_asessment-benchmarks.qmd",
"04e_assessment-projections.qmd",
"05_discussion.qmd",
"06_acknowledgments.qmd",
"07_references.qmd",
"08_tables.qmd",
"09_figures.qmd",
"10_notes.qmd",
"11_appendix.qmd"
)
sec_list2 <- add_section(
new_section = new_section,
Expand All @@ -645,10 +655,10 @@ create_template <- function(
stop("Defined customizations do not match one or all of the relative placement of a new section. Please review inputs.")
}
if (include_tables) {
sec_list1 <- c(sec_list1, "tables.qmd")
sec_list1 <- c(sec_list1, "08_tables.qmd")
}
if (include_figures) {
sec_list1 <- c(sec_list1, "figures.qmd")
sec_list1 <- c(sec_list1, "09_figures.qmd")
}
sec_list2 <- add_section(
new_section = new_section,
Expand Down Expand Up @@ -736,32 +746,38 @@ create_template <- function(
if (custom == FALSE) {
sections <- add_child(
c(
"executive_summary.qmd",
"introduction.qmd",
"data.qmd",
"modeling_approach.qmd",
"results.qmd",
"projections.qmd",
"discussion.qmd",
"acknowledgments.qmd",
"references.qmd",
"tables.qmd",
"figures.qmd",
"appendix.qmd"
"01_executive_summary.qmd",
"02_introduction.qmd",
"03_data.qmd",
"04a_assessment-configuration.qmd",
"04b_assessment-results.qmd",
"04c_assessment-sensitivity.qmd",
"04d_asessment-benchmarks.qmd",
"04e_assessment-projections.qmd",
"05_discussion.qmd",
"06_acknowledgments.qmd",
"07_references.qmd",
"08_tables.qmd",
"09_figures.qmd",
"10_notes.qmd",
"11_appendix.qmd"
),
label = c(
"executive_summary",
"introduction",
"data",
"modeling_approach",
"results",
"projections",
"discussion",
"acknowlesgements",
"references",
"tables",
"figures",
"appendix"
"01_executive_summary",
"02_introduction",
"03_data",
"04a_assessment-configuration",
"04b_assessment-results",
"04c_assessment-sensitivity",
"04d_asessment-benchmarks",
"04e_assessment-projections",
"05_discussion",
"06_acknowledgments",
"07_references",
"08_tables",
"09_figures",
"10_notes",
"11_appendix"
)
)
} else {
Expand All @@ -778,22 +794,25 @@ create_template <- function(

if (is.null(custom_sections)) {
sec_list1 <- list(
"executive_summary.qmd",
"introduction.qmd",
"data.qmd",
"modeling_approach.qmd",
"results.qmd",
"projections.qmd",
"discussion.qmd",
"acknowledgments.qmd",
"references.qmd",
"tables.qmd",
"figures.qmd",
"appendix.qmd"
"01_executive_summary.qmd",
"02_introduction.qmd",
"03_data.qmd",
"04a_assessment-configuration.qmd",
"04b_assessment-results.qmd",
"04c_assessment-sensitivity.qmd",
"04d_asessment-benchmarks.qmd",
"04e_assessment-projections.qmd",
"05_discussion.qmd",
"06_acknowledgments.qmd",
"07_references.qmd",
"08_tables.qmd",
"09_figures.qmd",
"10_notes.qmd",
"11_appendix.qmd"
)
sec_list2 <- add_section(
new_section = new_section,
new_section = section_location,
section_location = section_location,
custom_sections = sec_list1,
subdir = subdir
)
Expand All @@ -808,7 +827,7 @@ create_template <- function(
# Create new sections as .qmd in folder
sec_list2 <- add_section(
new_section = new_section,
new_section = section_location,
section_location = section_location,
custom_sections = sec_list1,
subdir = subdir
)
Expand Down
Loading

0 comments on commit 0c49a05

Please sign in to comment.