Skip to content
Open
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
656 changes: 656 additions & 0 deletions R/clean-variables.R

Large diffs are not rendered by default.

58 changes: 58 additions & 0 deletions R/file-sourcing.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# ==============================================================================
# Robust File Sourcing with Centralized Configuration
# ==============================================================================
#
# Configuration-based sourcing that uses here() with a single directory reference.
# Change DEVELOPMENT_R_DIR once to switch between development/production modes.
#
# Usage patterns:
# 1. R-to-R files: Use source_r_robust() (recommended) or source_r_with_fallback() (legacy)
# 2. Metadata files: Use here::here("inst", "extdata", ...)
# 3. Tests: Run from project root with testthat::test_file()
#
# DEVELOPMENT STATUS: Robust sourcing with centralized configuration
# LOCATION: development/flexible-missing-data-mvp/R/file-sourcing.R

# In package context, all R/ files are loaded automatically.
# The here package is not needed; DEVELOPMENT_R_DIR is only used outside package context.
DEVELOPMENT_R_DIR <- tryCatch(
here::here("development", "flexible-missing-data-mvp", "R"),
error = function(e) ""
)

# ==============================================================================
# ROBUST SOURCING FUNCTIONS
# ==============================================================================

#' Robust R file sourcing with centralized configuration
#'
#' Sources R files using centralized directory configuration.
#' Change DEVELOPMENT_R_DIR once to switch between dev/prod/test modes.
#'
#' @param filename Character. Name of R file to source
#' @param check_function Character. Function name to check if already loaded
#' @param verbose Logical. Print sourcing information
#' @export
source_r_robust <- function(filename, check_function = NULL, verbose = FALSE) {

# Skip if function already exists
if (!is.null(check_function) && exists(check_function)) {
if (verbose) cat("✓", check_function, "already loaded\n")
return(TRUE)
}

# Construct path using centralized configuration
source_path <- file.path(DEVELOPMENT_R_DIR, filename)

if (nzchar(source_path) && file.exists(source_path)) {
if (verbose) cat("Loading", filename, "from", source_path, "\n")
source(source_path)
return(TRUE)
} else {
# In package context, all functions are already available via R/ loading
if (verbose) cat("Skipping", filename, "(package context)\n")
return(TRUE)
}
}


Loading