Skip to content

Commit

Permalink
triming whitespace after magic string so filename is correct.
Browse files Browse the repository at this point in the history
  • Loading branch information
mduncans committed Oct 25, 2024
1 parent e76a2ac commit 6be6bab
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions R/add_tables.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -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")) {

Expand Down
2 changes: 1 addition & 1 deletion inst/scripts/add_figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion inst/scripts/add_figure_footnotes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion inst/scripts/add_table_footnotes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 6be6bab

Please sign in to comment.