From 6be6bab86783755c4bf7fdcb235c9e23e9bace5d Mon Sep 17 00:00:00 2001 From: Matt Smith Date: Fri, 25 Oct 2024 13:18:00 +0000 Subject: [PATCH] triming whitespace after magic string so filename is correct. --- R/add_tables.R | 4 ++-- inst/scripts/add_figure.py | 2 +- inst/scripts/add_figure_footnotes.py | 2 +- inst/scripts/add_table_footnotes.py | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/R/add_tables.R b/R/add_tables.R index 24ca87c..c6b7b6b 100644 --- a/R/add_tables.R +++ b/R/add_tables.R @@ -28,7 +28,7 @@ #' ) #' } add_tables <- function(docx_in, docx_out, tables_path, debug = F) { - log4r::debug(.le$logger, "Starting add_tables_by_magic_string function") + log4r::debug(.le$logger, "Starting add_tables function") tictoc::tic() if (!file.exists(docx_in)) { @@ -69,7 +69,7 @@ add_tables <- function(docx_in, docx_out, tables_path, debug = F) { if (length(matches) > 0) { log4r::info(.le$logger, paste0("Found magic string: ", matches[1], " in paragraph ", i)) - table_name <- gsub("\\{rpfy\\}:", "", matches[1]) # Remove "{rpfy}:" + table_name <- gsub("\\{rpfy\\}:", "", matches[1]) |> trimws() # Remove "{rpfy}:" table_file <- file.path(tables_path, table_name) #if (tools::file_ext(table_file) %in% c("RDS", "csv")) { diff --git a/inst/scripts/add_figure.py b/inst/scripts/add_figure.py index 60f7a80..8a25aca 100644 --- a/inst/scripts/add_figure.py +++ b/inst/scripts/add_figure.py @@ -20,7 +20,7 @@ def add_figure(docx_in, docx_out, figure_dir, fig_width, fig_height): print(f"Duplicate figure names found in paragraph {i+1}.") for match in matches: # Extract the image directory from the match - figure_name = match.replace("{rpfy}:", "") + figure_name = match.replace("{rpfy}:", "").strip() found_magic_strings.append(figure_name) image_path = os.path.join(figure_dir, figure_name) diff --git a/inst/scripts/add_figure_footnotes.py b/inst/scripts/add_figure_footnotes.py index c2ca554..3c5bf4c 100644 --- a/inst/scripts/add_figure_footnotes.py +++ b/inst/scripts/add_figure_footnotes.py @@ -26,7 +26,7 @@ def add_figure_footnotes(docx_in, docx_out, figure_dir, footnotes_yaml): if matches: for match in matches: # Generalized extraction of the figure name - figure_name = match.replace("{rpfy}:", "") + figure_name = match.replace("{rpfy}:", "").strip() if figure_name in os.listdir(figure_dir): object_name, extension = os.path.splitext(figure_name) diff --git a/inst/scripts/add_table_footnotes.py b/inst/scripts/add_table_footnotes.py index edacbe6..61441bd 100644 --- a/inst/scripts/add_table_footnotes.py +++ b/inst/scripts/add_table_footnotes.py @@ -26,7 +26,7 @@ def add_table_footnotes(docx_in, docx_out, table_dir, footnotes_yaml): if matches: for match in matches: # Generalized extraction of the figure name - table_name = match.replace("{rpfy}:", "") + table_name = match.replace("{rpfy}:", "").strip() if table_name in os.listdir(table_dir): object_name, extension = os.path.splitext(table_name) metadata_file = os.path.join(table_dir, f"{object_name}_{extension[1::]}_metadata.json")