Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Imports:
fs,
glue,
gt,
journals,
purrr,
stats,
stringi,
Expand All @@ -49,7 +50,8 @@ Suggests:
testthat (>= 3.0.0),
withr
Remotes:
nmfs-ost/stockplotr
nmfs-ost/stockplotr,
nmfs-ost/journals
Config/Needs/website: quarto
Config/roxygen2/version: 8.1.0
Config/testthat/edition: 3
Expand Down
35 changes: 17 additions & 18 deletions R/create_template.R
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,11 @@
#'
#' Default: NULL
#'
#' @param bib_file File path to bibliography file (`.bib`) used for citing references in
#' the report
#' @param bib_file File path to additional bibliography file (`.bib`) used for citing references in
#' the report. By default, all bibliogrphy files from the journals package and
#' references for all NMFS stock assessment reports are provided.
#'
#' Default: "asar_references.bib"
#' Default: NULL
#'
#' @param new_template TRUE/FALSE; Create a new template? If true,
#' will pull the last saved stock assessment report skeleton.
Expand Down Expand Up @@ -249,7 +250,7 @@ create_template <- function(
tables_dir = getwd(),
figures_dir = getwd(),
spp_image = NULL,
bib_file = "asar_references.bib",
bib_file = NULL,
new_template = TRUE,
rerender_skeleton = FALSE,
custom_sections = NULL,
Expand Down Expand Up @@ -501,16 +502,18 @@ create_template <- function(
}

# Add bib file
if (bib_file == "asar_references.bib") {
bib_loc <- system.file("resources", "asar_references.bib", package = "asar")
bib_name <- bib_file
if (is.null(bib_file)) {
if (!rerender_skeleton) {
bib_dir <- file.path(subdir, "bibliography_files")
dir.create(bib_dir, recursive = FALSE)
journals::download_bibs(bib_dir)
bib_file <- list.files(bib_dir, pattern = ".bib", full.names = TRUE)
bib_name <- list.files(bib_dir, pattern = ".bib", full.names = FALSE)
} else {
bib_name <- NULL
}
} else {
# check if enter file exists
# if (!file.exists(bib_file)) stop(".bib file not found.")
cli::cli_alert_warning("Bibliography file {bib_file} not in the report directory.")
cli::cli_alert_info("The file will not be read in on render if not in the same path as the skeleton file.")

bib_loc <- bib_file # dirname(bib_file)
file.copy(bib_file, subdir, overwrite = TRUE) |> suppressWarnings()
bib_name <- stringr::str_extract(bib_file, "[^/]+$") # utils::tail(stringr::str_split(bib_file, "/")[[1]], n = 1)
}

Expand Down Expand Up @@ -576,7 +579,7 @@ create_template <- function(
} else {
#### Copy template files to report folder ----
# Check if there are already files in the folder
if (length(list.files(subdir)) < 2) {
if (length(list.files(subdir)) < 3) {
# copy quarto files
file.copy(file.path(current_folder, files_to_copy), new_folder, overwrite = FALSE)
# copy before-body tex
Expand All @@ -587,8 +590,6 @@ create_template <- function(
create_inheader_tex(species = species, year = year, subdir = supdir)
# Copy species image from package
file.copy(spp_image, supdir, overwrite = FALSE) |> suppressWarnings()
# Copy bib file
file.copy(bib_loc, subdir, overwrite = TRUE) |> suppressWarnings()
# Copy us doc logo
file.copy(system.file("resources", "us_doc_logo.png", package = "asar"), supdir, overwrite = FALSE) |> suppressWarnings()
# Copy glossary
Expand Down Expand Up @@ -645,8 +646,6 @@ create_template <- function(
create_inheader_tex(species = species, year = year, subdir = supdir)
# Copy species image from package
file.copy(spp_image, supdir, overwrite = FALSE) |> suppressWarnings()
# Copy bib file
file.copy(bib_loc, subdir, overwrite = TRUE) |> suppressWarnings()
# Copy us doc logo
file.copy(system.file("resources", "us_doc_logo.png", package = "asar"), supdir, overwrite = FALSE) |> suppressWarnings()
# Copy glossary
Expand Down
24 changes: 6 additions & 18 deletions R/create_yaml.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
#' @param author_list A list of strings containing pre-formatted author names
#' and affiliations that would be found in the format in a yaml of a quarto
#' file when using base R function `cat()`.
#' @param bib_name Name of a bib file being added into the yaml. For example,
#' "asar.bib".
#'
#' @return Create a string indicating the important formatting pieces for a
#' quarto file for a stock assessment report.
Expand Down Expand Up @@ -64,7 +62,7 @@ create_yaml <- function(
spp_image = NULL,
year = NULL,
bib_name = NULL,
bib_file = "asar_references.bib",
bib_file = NULL,
author_list = NULL,
title = "[TITLE]",
rerender_skeleton = FALSE,
Expand Down Expand Up @@ -189,20 +187,11 @@ create_yaml <- function(
} # close if params to be included in template

# add bib file name
if (bib_name != "asar_references.bib") {
# check if input bib file contains a path
if (file.exists(bib_file)) {
cli::cli_alert("Copying bibliography file to report folder...")
file.copy(bib_file, file_dir)
# bib_file_only <- stringr::str_extract(bib_file, "[^/]+$")
bib_format <- paste("- ", bib_name, sep = "")
} else if (!file.exists(file.path(file_dir, bib_file))) {
cli::cli_alert_warning("Bibliography file {bib_file} is not in the report directory. The file will not be read in on render if it is not in the same path as the skeleton file.",
wrap = TRUE
)
bib_format <- paste("- ", bib_name, sep = "")
}
if (!is.null(bib_name)) {
new_bib_name <- bib_name[grepl(bib_name), new_bibs]
bib_format <- paste("- ", bib_name, sep = "")
}

yaml <- paste(yaml, collapse = " \n")
} else { # not rerendering skeleton
# Creating YAML
Expand Down Expand Up @@ -326,7 +315,7 @@ create_yaml <- function(
bib <- glue::glue(
"bibliography: ", "\n"
)
bib_all <- paste0(" ", "- ", bib_file, "\n", collapse = "")
bib_all <- paste0(" ", "- ", paste0("bibliography_files/", bib_name), "\n", collapse = "")
bib <- glue::glue("{bib} \n {bib_all}")
yaml <- paste(yaml, bib, sep = "")
# add citation style
Expand All @@ -335,7 +324,6 @@ create_yaml <- function(
"csl: support_files/cjfas.csl\n"
)
# }
# add in else statement once a national .bib file is made

# Close yaml
yaml <- glue::glue("{yaml}---\n")
Expand Down
Loading
Loading