Skip to content

Conversation

@Schiano-NOAA
Copy link
Collaborator

What is the feature?

  • Fixed minor issues with parts of the rerendering process
  • Fixed misplacement of custom sections found when running examples for workshops

How have you implemented the solution?

  • See code - fixed small issues in multiple functions

Does the PR impact any other area of the project, maybe another repo?

*no

@github-actions
Copy link
Contributor

New version checklist

  • Package version in DESCRIPTION has been updated
  • Release notes have been drafted/published
  • Cheatsheet content has been updated (if applicable)
  • Cheatsheet version has been updated

@github-actions
Copy link
Contributor

Checklist

  • PR base branch is accurate
  • Is the code concise?
  • Comments are clear and useful.
  • Can you remove or combine any arguments?
  • Do argument contain defaults (if appliable)?
  • Code is documented and example provided (Roxygen).
  • Did you make a test (testthat)?
  • Was this tested under multiple scenarios?
  • Did you run devtools::check()?

@github-actions
Copy link
Contributor

Code Metrics Report

Coverage Code to Test Ratio Test Execution Time
37.8% 1:0.2 27s

Code coverage of files in pull request scope (48.2%)

Files Coverage
R/add_authors.R 47.0%
R/create_citation.R 71.2%
R/create_template.R 41.5%
R/create_title.R 91.8%
R/create_yaml.R 51.2%

Reported by octocov

@Schiano-NOAA Schiano-NOAA marked this pull request as ready for review January 15, 2026 19:42
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This hotfix addresses issues with the rerendering process and custom section placement that were discovered during workshop examples. The changes include fixes for parameter handling, region extraction, file path references, and section ordering.

Changes:

  • Fixed conditional logic for author addition and region parameter handling in YAML creation
  • Corrected species name extraction and region handling during template rerendering
  • Fixed custom section ordering to properly include tables and figures documents

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
R/create_yaml.R Fixed author list conditional check, updated species parameter matching, added region parameter handling, and corrected output file naming
R/create_title.R Added null check for spp_latin parameter before applying LaTeX formatting
R/create_template.R Fixed region extraction, species name handling, citation updates, year fallback logic, and custom section ordering
R/create_citation.R Removed commented-out code for authorship lookup
R/add_authors.R Fixed loop iteration to use correct vector length
Comments suppressed due to low confidence (1)

R/create_template.R:812

  • This entire params_chunk creation block (lines 791-813) is duplicated from the else branch above (lines 767-789). The code should be refactored to avoid this duplication, perhaps by moving this logic outside the if-else statement.
      paste0(
        "# Parameters \n",
        "spp <- params$species \n",
        "SPP <- params$spp \n",
        "species <- params$species \n",
        "spp_latin <- params$spp_latin \n",
        "office <- params$office",
        if (!is.null(region)) {
          paste0(
            "\n",
            "region <- params$region"
          )
        },
        if (!is.null(param_names)) {
          paste0(
            "\n",
            paste0(param_names, " <- ", "params$", param_names, collapse = " \n")
          )
        }
      ),
      label = "doc_parameters"

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

)
}
if (!is.null(param_values) & !is.null(param_names)) {
for (i in length(param_value)) {
Copy link

Copilot AI Jan 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The loop uses length(param_value) which creates a sequence from 1 to a single number, but the variable name is param_value (singular) instead of param_values (plural) which is the actual parameter name. This should be for (i in seq_along(param_values)).

Suggested change
for (i in length(param_value)) {
for (i in seq_along(param_values)) {

Copilot uses AI. Check for mistakes.
Comment on lines +88 to +91
if (length(add_authors) > 0) {
add_authors <- unlist(stringr::str_split(author_list, "\n"))
# remove trailing \n from each author entry
add_authors <- gsub("\n", "", add_authors)
Copy link

Copilot AI Jan 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variable add_authors is checked for length before it is defined. This will cause an error since add_authors is first created on line 89. Move the length check to after the variable is created, or initialize add_authors before this check.

Suggested change
if (length(add_authors) > 0) {
add_authors <- unlist(stringr::str_split(author_list, "\n"))
# remove trailing \n from each author entry
add_authors <- gsub("\n", "", add_authors)
add_authors <- unlist(stringr::str_split(author_list, "\n"))
# remove trailing \n from each author entry
add_authors <- gsub("\n", "", add_authors)
if (length(add_authors) > 0) {

Copilot uses AI. Check for mistakes.
region = region,
type = type,
year = year
year = ifelse(is.na(year), format(as.POSIXct(Sys.Date(), format = "%YYYY-%mm-%dd"), "%Y"), year)
Copy link

Copilot AI Jan 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The date format string '%YYYY-%mm-%dd' is incorrect. It should be '%Y-%m-%d' (single Y, single m, single d). The incorrect format will cause the POSIXct conversion to fail.

Copilot uses AI. Check for mistakes.
@sbreitbart-NOAA sbreitbart-NOAA linked an issue Jan 15, 2026 that may be closed by this pull request
@sbreitbart-NOAA
Copy link
Collaborator

Reran the answers to the advanced create_template() exercises.

This worked!

asar::create_template(
    authors = c("Samantha Schiano" = "OST"),
    custom = TRUE,
    custom_sections = c("executive_summary", "introduction")
)

This left an empty cover: in the yaml, saved the param species: as "species" and spp_latin empty, but those are minor things that can be fixed at another time (and I think you already know about?):

asar::create_template(
  rerender_skeleton = TRUE,
  species = "Petrale sole",
  spp_latin = "Eopsetta jordani",
  file_dir = file.path("report")
)

Also, the bug in this issue was resolved! #410

Copy link
Collaborator

@sbreitbart-NOAA sbreitbart-NOAA left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't done as extensive testing as I usually would, but I tested out a few distinct situations, including the code in the workshop, and it either works perfectly or seems good enough (see my comment). Nice job!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: create_template() custom sections not added properly

3 participants