From a672199df5edb05a96c208891fe44ba246d711d3 Mon Sep 17 00:00:00 2001 From: jacobdum Date: Tue, 14 Oct 2025 01:07:28 +0000 Subject: [PATCH 1/9] argus trace quick fix --- DESCRIPTION | 1 + R/write_object_metadata.R | 67 ++++++++++++++++++++++++--------------- 2 files changed, 42 insertions(+), 26 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index ae93854..3377411 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -40,6 +40,7 @@ Imports: purrr, rlang, rstudioapi, + this.path, tictoc, yaml Suggests: diff --git a/R/write_object_metadata.R b/R/write_object_metadata.R index 78e45fa..780ca81 100644 --- a/R/write_object_metadata.R +++ b/R/write_object_metadata.R @@ -51,35 +51,50 @@ write_object_metadata <- function( source_path <- tryCatch( { - # Check if the script is being sourced - src_path <- if (!is.null(sys.frame(1)$ofile)) { - normalizePath(sys.frame(1)$ofile) # Path of the currently sourced file - } else if (!is.null(knitr::current_input())) { - normalizePath(knitr::current_input()) - } else if ( - requireNamespace("rstudioapi", quietly = TRUE) && - rstudioapi::isAvailable() - ) { - context <- rstudioapi::getSourceEditorContext() - if (!is.null(context$path) && nzchar(context$path)) { - normalizePath(context$path) + # this.path + if (requireNamespace("this.path", quietly = TRUE)) { + sp <- this.path::this.path() + if (!is.null(sp) && nzchar(sp)) { + normalizePath(sp) } else { - normalizePath("Object created from console") + stop("this.path did not return a valid script path") } - } else if (!is.null(rmarkdown::metadata$input_file)) { - normalizePath(rmarkdown::metadata$input_file) - } else if (!is.null(getOption("knitr.in.file"))) { - normalizePath(getOption("knitr.in.file")) - } else if (testthat::is_testing()) { - normalizePath(testthat::test_path()) } else { - stop("Unable to detect input file") + stop("package this.path not available") } - src_path }, - error = function(e) { - log4r::error(.le$logger, "Error detecting source file path") - stop(e) + error = function(e1) { + # previous fallbacks + tryCatch( + { + if (!is.null(sys.frame(1)$ofile)) { + normalizePath(sys.frame(1)$ofile) + } else if (!is.null(knitr::current_input())) { + normalizePath(knitr::current_input()) + } else if ( + requireNamespace("rstudioapi", quietly = TRUE) && + rstudioapi::isAvailable() + ) { + context <- rstudioapi::getSourceEditorContext() + if (!is.null(context$path) && nzchar(context$path)) { + normalizePath(context$path) + } else { + normalizePath("Object created from console") + } + } else if (!is.null(rmarkdown::metadata$input_file)) { + normalizePath(rmarkdown::metadata$input_file) + } else if (!is.null(getOption("knitr.in.file"))) { + normalizePath(getOption("knitr.in.file")) + } else if (testthat::is_testing()) { + normalizePath(testthat::test_path()) + } else { + stop("Unable to detect input file") + } + }, + error = function(e2) { + log4r::warn(.le$logger, "Unable to detect input file; falling back to working directory") + } + ) } ) @@ -87,12 +102,12 @@ write_object_metadata <- function( # Find project root directory (containing .*_init.json) project_root <- find_project_root() - + if (is.null(project_root)) { log4r::error(.le$logger, "Could not find project root directory (no *_init.json file found)") stop("Could not find project root directory. Make sure you're in a reportifyr project (run initialize_report_project() first)") } - + # Convert source path to relative path from project root source_path_relative <- fs::path_rel(source_path, project_root) log4r::info(.le$logger, paste0("Source file path (relative): ", source_path_relative)) From 3be81e50c41240d4c2b239d60a8beeea0366a9e3 Mon Sep 17 00:00:00 2001 From: jacobdum Date: Sun, 19 Oct 2025 23:21:42 +0000 Subject: [PATCH 2/9] new utils fxn to capture quarto render --- R/utils.R | 61 +++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 55 insertions(+), 6 deletions(-) diff --git a/R/utils.R b/R/utils.R index 11b51c6..5926e85 100644 --- a/R/utils.R +++ b/R/utils.R @@ -151,7 +151,7 @@ get_uv_path <- function(quiet = FALSE) { # Use default expansion home_dir <- path.expand("~") } - + if (.Platform$OS.type == "windows") { # Windows paths uv_paths <- c( @@ -212,25 +212,74 @@ get_uv_version <- function(uv_path) { #' @noRd find_project_root <- function(start_path = getwd()) { current_path <- normalizePath(start_path) - + while (TRUE) { # Look for any .*_init.json file (e.g., .report_init.json, .custom_init.json) init_files <- list.files(current_path, pattern = "^\\.[^.]*_init\\.json$", full.names = TRUE, all.files = TRUE) if (length(init_files) > 0) { return(current_path) } - + # Move up one directory parent_path <- dirname(current_path) - + # If we've reached the root directory, stop if (parent_path == current_path) { break } - + current_path <- parent_path } - + # Return NULL if not found return(NULL) } + +detect_quarto_render <- function() { + log4r::debug(.le$logger, "Starting detect_quarto_render()") + + # --- Detect Quarto context --- + quarto_vars <- Sys.getenv(c("QUARTO_PROJECT_ROOT", "QUARTO_BIN_PATH", "QUARTO_RENDER_TOKEN")) + is_quarto <- any(quarto_vars != "") + log4r::debug(.le$logger, paste0( + "Quarto vars: ", + paste(names(quarto_vars), quarto_vars, sep = "=", collapse = "; "), + " | is_quarto = ", is_quarto + )) + + if (!is_quarto) { + log4r::debug(.le$logger, "Not running in a Quarto context — returning NULL") + return(NULL) + } + + # --- Get current input --- + current <- tryCatch(knitr::current_input(), error = function(e) NULL) + log4r::debug(.le$logger, paste0("knitr::current_input() returned: ", ifelse(is.null(current), "NULL", current))) + + # --- Validate current file pattern --- + if (is.null(current) || !grepl("\\.(Rmd|rmarkdown)$", current, ignore.case = TRUE)) { + log4r::debug(.le$logger, "Current input is NULL or not an .Rmd/.rmarkdown file — returning NULL") + return(NULL) + } + + # --- Attempt to resolve .qmd equivalent --- + qmd_candidate <- sub("\\.(rmd|rmarkdown)$", ".qmd", basename(current)) + project_root <- Sys.getenv("QUARTO_PROJECT_ROOT", unset = getwd()) + qmd_path <- file.path(project_root, qmd_candidate) + log4r::debug(.le$logger, paste0("Candidate .qmd path: ", qmd_path)) + + if (file.exists(qmd_path)) { + log4r::info(.le$logger, paste0( + "Detected Quarto render: .Rmd intermediate '", current, + "' mapped to existing .qmd: ", qmd_path + )) + return(normalizePath(qmd_path)) + } else { + log4r::warn(.le$logger, paste0( + "Quarto environment detected, but .qmd not found at: ", qmd_path, + " — returning NULL" + )) + return(NULL) + } +} + From 7c3f5247418fe8e0dc40ec6eecdc71f44694ec89 Mon Sep 17 00:00:00 2001 From: jacobdum Date: Sun, 19 Oct 2025 23:21:57 +0000 Subject: [PATCH 3/9] implement new utils fxn and remove fallbacks --- R/write_object_metadata.R | 73 ++++++++++++++------------------------- 1 file changed, 26 insertions(+), 47 deletions(-) diff --git a/R/write_object_metadata.R b/R/write_object_metadata.R index 780ca81..3bf2563 100644 --- a/R/write_object_metadata.R +++ b/R/write_object_metadata.R @@ -49,56 +49,35 @@ write_object_metadata <- function( hash <- digest::digest(file = object_file, algo = "blake3") log4r::info(.le$logger, paste0("Generated file hash: ", hash)) - source_path <- tryCatch( - { - # this.path - if (requireNamespace("this.path", quietly = TRUE)) { - sp <- this.path::this.path() - if (!is.null(sp) && nzchar(sp)) { - normalizePath(sp) - } else { - stop("this.path did not return a valid script path") - } + source_path <- tryCatch({ + qmd_path <- detect_quarto_render() + if (!is.null(qmd_path)) { + log4r::info(.le$logger, + paste0("Detected Quarto render; using .qmd file: ", qmd_path)) + qmd_path + } else if (requireNamespace("this.path", quietly = TRUE)) { + sp <- this.path::this.path() + if (!is.null(sp) && nzchar(sp)) { + sp <- normalizePath(sp) + log4r::info(.le$logger, + paste0("Source path detected via this.path: ", sp)) + sp } else { - stop("package this.path not available") + log4r::warn(.le$logger, + "this.path did not return a valid script path; setting placeholder") + "SOURCE_PATH_NOT_DETECTED" } - }, - error = function(e1) { - # previous fallbacks - tryCatch( - { - if (!is.null(sys.frame(1)$ofile)) { - normalizePath(sys.frame(1)$ofile) - } else if (!is.null(knitr::current_input())) { - normalizePath(knitr::current_input()) - } else if ( - requireNamespace("rstudioapi", quietly = TRUE) && - rstudioapi::isAvailable() - ) { - context <- rstudioapi::getSourceEditorContext() - if (!is.null(context$path) && nzchar(context$path)) { - normalizePath(context$path) - } else { - normalizePath("Object created from console") - } - } else if (!is.null(rmarkdown::metadata$input_file)) { - normalizePath(rmarkdown::metadata$input_file) - } else if (!is.null(getOption("knitr.in.file"))) { - normalizePath(getOption("knitr.in.file")) - } else if (testthat::is_testing()) { - normalizePath(testthat::test_path()) - } else { - stop("Unable to detect input file") - } - }, - error = function(e2) { - log4r::warn(.le$logger, "Unable to detect input file; falling back to working directory") - } - ) + } else { + log4r::warn(.le$logger, + "Unable to detect source path via Quarto or this.path(); setting placeholder") + "SOURCE_PATH_NOT_DETECTED" } - ) - - log4r::info(.le$logger, paste0("Source file path detected: ", source_path)) + }, + error = function(e) { + log4r::warn(.le$logger, + paste0("Error detecting source path: ", e$message)) + "SOURCE_PATH_NOT_DETECTED" + }) # Find project root directory (containing .*_init.json) project_root <- find_project_root() From 0eeabd4e4146c38d054a0c9af1e11d83345b174a Mon Sep 17 00:00:00 2001 From: jacobdum Date: Sun, 19 Oct 2025 23:24:51 +0000 Subject: [PATCH 4/9] upversion and remove rstudioapi --- DESCRIPTION | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 3377411..c2203b6 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: reportifyr Title: Reproducible Reporting Made Simple with R -Version: 0.3.2 +Version: 0.3.3 Authors@R: c( person("Jacob", "Dumbleton", , "jacob@a2-ai.com", role = c("aut", "cre")), person("Matthew", "Smith", , "matthews@a2-ai.com", role = "aut"), @@ -39,7 +39,6 @@ Imports: processx, purrr, rlang, - rstudioapi, this.path, tictoc, yaml From 49bd20b37f8772233af080d4855e8d7d90f9af41 Mon Sep 17 00:00:00 2001 From: jacobdum Date: Sun, 19 Oct 2025 23:42:52 +0000 Subject: [PATCH 5/9] update NEWS.md --- NEWS.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/NEWS.md b/NEWS.md index f18c4fe..0274d7d 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,8 @@ +# reportifyr 0.3.3 +## Bug Fixes + +* Fixed an issue where the source path of an object being written out with `write_object_metadata()` during a quarto render was being captured as the intermediate `.rmarkdown`. + # reportifyr 0.3.2 ## Improvements From 8e45780a529c66d910a34dd88929668b983a1b6a Mon Sep 17 00:00:00 2001 From: jacobdum Date: Tue, 21 Oct 2025 16:59:43 +0000 Subject: [PATCH 6/9] Fix nonascii logs --- R/utils.R | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/R/utils.R b/R/utils.R index 5926e85..a79c5ce 100644 --- a/R/utils.R +++ b/R/utils.R @@ -248,7 +248,7 @@ detect_quarto_render <- function() { )) if (!is_quarto) { - log4r::debug(.le$logger, "Not running in a Quarto context — returning NULL") + log4r::debug(.le$logger, "Not running in a Quarto context, returning NULL") return(NULL) } @@ -258,7 +258,7 @@ detect_quarto_render <- function() { # --- Validate current file pattern --- if (is.null(current) || !grepl("\\.(Rmd|rmarkdown)$", current, ignore.case = TRUE)) { - log4r::debug(.le$logger, "Current input is NULL or not an .Rmd/.rmarkdown file — returning NULL") + log4r::debug(.le$logger, "Current input is NULL or not an .Rmd/.rmarkdown file, returning NULL") return(NULL) } @@ -277,7 +277,7 @@ detect_quarto_render <- function() { } else { log4r::warn(.le$logger, paste0( "Quarto environment detected, but .qmd not found at: ", qmd_path, - " — returning NULL" + ", returning NULL" )) return(NULL) } From 232a1ba51f9bd2eb100508a7eb47387a1bf101bc Mon Sep 17 00:00:00 2001 From: jacobdum Date: Tue, 21 Oct 2025 19:39:23 +0000 Subject: [PATCH 7/9] address missing dep --- .github/workflows/R-CMD-check.yaml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml index 20fdee6..e271f7e 100644 --- a/.github/workflows/R-CMD-check.yaml +++ b/.github/workflows/R-CMD-check.yaml @@ -78,6 +78,15 @@ jobs: echo "All system dependencies are present" fi + - name: rv-sysdeps-install (macOS) + if: runner.os == 'macOS' + run: | + brew install gettext + prefix=$(brew --prefix gettext) + echo "LDFLAGS=-L${prefix}/lib $LDFLAGS" >> $GITHUB_ENV + echo "CPPFLAGS=-I${prefix}/include $CPPFLAGS" >> $GITHUB_ENV + echo "PKG_CONFIG_PATH=${prefix}/lib/pkgconfig:$PKG_CONFIG_PATH" >> $GITHUB_ENV + - name: rv-sync run: rv sync if: runner.os != 'Windows' From fe044248635c80287837d936705787ef658b78f9 Mon Sep 17 00:00:00 2001 From: jacobdum Date: Tue, 21 Oct 2025 19:56:47 +0000 Subject: [PATCH 8/9] remove workflow dep, add dep to .toml --- .github/workflows/R-CMD-check.yaml | 9 --------- rproject.toml | 2 ++ 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml index e271f7e..20fdee6 100644 --- a/.github/workflows/R-CMD-check.yaml +++ b/.github/workflows/R-CMD-check.yaml @@ -78,15 +78,6 @@ jobs: echo "All system dependencies are present" fi - - name: rv-sysdeps-install (macOS) - if: runner.os == 'macOS' - run: | - brew install gettext - prefix=$(brew --prefix gettext) - echo "LDFLAGS=-L${prefix}/lib $LDFLAGS" >> $GITHUB_ENV - echo "CPPFLAGS=-I${prefix}/include $CPPFLAGS" >> $GITHUB_ENV - echo "PKG_CONFIG_PATH=${prefix}/lib/pkgconfig:$PKG_CONFIG_PATH" >> $GITHUB_ENV - - name: rv-sync run: rv sync if: runner.os != 'Windows' diff --git a/rproject.toml b/rproject.toml index dd8015f..2999f0e 100644 --- a/rproject.toml +++ b/rproject.toml @@ -7,9 +7,11 @@ r_version = "4.4" repositories = [ #{ alias = "PRISM", url = "https://prism.dev.a2-ai.cloud/rpkgs/stratus/2025-07-28/" }, {alias = "ppm", url = "https://packagemanager.posit.co/cran/latest"}, + {alias = "CRAN", url = "https://cran.r-project.org"}, ] dependencies = [ "devtools", {name = "reportifyr", path = ".", dependencies_only = true, install_suggestions = true }, + {name = "gdtools", repository = "CRAN"}, ] From 8e7d69b6e19d20c319324e977b49913c9782be05 Mon Sep 17 00:00:00 2001 From: jacobdum Date: Thu, 23 Oct 2025 14:21:29 +0000 Subject: [PATCH 9/9] simplify logs --- R/utils.R | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/R/utils.R b/R/utils.R index a79c5ce..23116b9 100644 --- a/R/utils.R +++ b/R/utils.R @@ -241,11 +241,7 @@ detect_quarto_render <- function() { # --- Detect Quarto context --- quarto_vars <- Sys.getenv(c("QUARTO_PROJECT_ROOT", "QUARTO_BIN_PATH", "QUARTO_RENDER_TOKEN")) is_quarto <- any(quarto_vars != "") - log4r::debug(.le$logger, paste0( - "Quarto vars: ", - paste(names(quarto_vars), quarto_vars, sep = "=", collapse = "; "), - " | is_quarto = ", is_quarto - )) + log4r::debug(.le$logger, paste0("Quarto environment vars detected: ", is_quarto)) if (!is_quarto) { log4r::debug(.le$logger, "Not running in a Quarto context, returning NULL")