Performs comprehensive health checks on a boilerplate database to identify potential issues such as orphaned variables, empty entries, and structural problems. Can optionally generate a detailed report.
Arguments
- db
List. The database to check (can be unified or single category).
- fix
Logical. If TRUE, attempts to fix issues where possible. Default FALSE.
- report
Character or NULL. If a file path is provided, saves a detailed report. If "text", returns the report as a character string. If NULL (default), returns the health check object.
- quiet
Logical. If TRUE, suppresses non-critical messages. Default FALSE.
Value
Depends on the report
parameter:
If
report = NULL
: A list with class "boilerplate_health" containing summary, issues, stats, and fixed itemsIf
report = "text"
: A character string containing the detailed reportIf
report
is a file path: Invisibly returns the file path after saving report
Examples
# \donttest{
# Create temporary directory for example
temp_dir <- tempfile()
dir.create(temp_dir)
# Initialise and import database
boilerplate_init(data_path = temp_dir, create_dirs = TRUE,
confirm = FALSE, quiet = TRUE)
db <- boilerplate_import(data_path = temp_dir, quiet = TRUE)
# Check database health
health <- boilerplate_check_health(db)
#> ℹ Checking database health...
#> ! Found 1 issue (1 warning, 0 info)
print(health)
#>
#> Database Health Report
#> ======================
#> Checked at: 2025-06-24 21:41:50
#>
#> Summary
#> -------
#> Status: ⚠ ISSUES FOUND
#> Total entries: 17
#> Categories: 6
#> Template variables: 0
#> Documented variables: 0 (0.0%)
#>
#> Issues Found
#> ------------
#>
#> warning: Empty Entries (12)
#> Empty or NULL entries found
#>
# Generate text report
report_text <- boilerplate_check_health(db, report = "text")
#> ℹ Checking database health...
#> ! Found 1 issue (1 warning, 0 info)
cat(report_text)
#>
#> Database Health Report
#> ======================
#> Checked at: 2025-06-24 21:41:50
#>
#> Summary
#> -------
#> Status: ⚠ ISSUES FOUND
#> Total entries: 17
#> Categories: 6
#> Template variables: 0
#> Documented variables: 0 (0.0%)
#>
#> Issues Found
#> ------------
#>
#> warning: Empty Entries (12)
#> Empty or NULL entries found
#>
#>
#> Detailed Issue Information
#> =========================
# Save report to file
report_file <- file.path(temp_dir, "health_report.txt")
boilerplate_check_health(db, report = report_file)
#> ℹ Checking database health...
#> ! Found 1 issue (1 warning, 0 info)
#> ✔ Health report saved to /var/folders/q9/lkcn14l97mb6mkhbxsxrpr4w0000gn/T//RtmpSFGi7F/file9ec22eceb344/health_report.txt
# Check and fix issues
health <- boilerplate_check_health(db, fix = TRUE)
#> ℹ Checking database health...
#> ✔ Fixed 12 issues
#> ! Found 2 issues (2 warnings, 0 info)
# Get the fixed database
if (health$summary$issues_fixed > 0) {
db <- attr(health, "fixed_db")
}
# Clean up
unlink(temp_dir, recursive = TRUE)
# }