Error in `boilerplate_export(db = unified_db, data_path = export_dir, output_file = "exported.rds", 
    save_by_category = TRUE, quiet = TRUE, confirm = FALSE)`: Directory does not exist: D:\temp\2025_06_12_16_45_17_25820\RtmpwPIMz6\test_import_export2dbac140f1e97/export/projects/default/data. Set create_dirs=TRUE to create it.

# Unit tests for import/export functions
test_that("boilerplate_import and boilerplate_export work correctly", {
# Create unique temp directory for this test
data_dir <- file.path(temp_base, "boilerplate", "data")
dir.create(data_dir, recursive = TRUE, showWarnings = FALSE)
# Save test databases with correct filenames
category = NULL,  # NULL imports all categories
# With save_by_category, should create separate files
test_that("boilerplate_export handles selective export", {
test_that("boilerplate_export handles wildcard selection", {
longitudinal = list(default = "Longitudinal"),
crosssectional = list(default = "Cross-sectional")
methods = list(sample = list(default = "Test")),
measures = list(test = list(name = "test"))
data_dir <- file.path(temp_dir, "boilerplate", "data")
# Save specific category (also JSON by default)
test_that("boilerplate_import handles various database formats", {
# Test importing individual category databases
main = list(description = "Main analysis", text = "Analysis text")
primary = list(description = "Primary results", text = "Results text")
imported_methods <- boilerplate_import(category = "methods", data_path = data_dir, quiet = TRUE)
imported_all <- boilerplate_import(category = NULL, data_path = data_dir, quiet = TRUE)
methods = list(test = list(description = "Test")),
results = list(test = list(description = "Test"))
imported_unified <- boilerplate_import(category = NULL, data_path = data_dir, quiet = TRUE)
test_that("boilerplate_export handles complex selection patterns", {
lmtp = list(description = "LMTP", text = "LMTP method"),
gcomp = list(description = "G-comp", text = "G-computation")
regression = list(description = "Regression", text = "Linear regression")
random = list(description = "Random", text = "Random sampling"),
stratified = list(description = "Stratified", text = "Stratified sampling")
main = list(description = "Main", text = "Main results"),
sensitivity = list(description = "Sensitivity", text = "Sensitivity results")
# Check non-selected elements are absent
# Test export with no selection (full export)
test_that("boilerplate_save handles different save modes", {
methods = list(test = list(description = "Test method")),
results = list(test = list(description = "Test result")),
measures = list(test = list(name = "test", description = "Test measure"))
# Test save unified with specific output directory
category = NULL,  # NULL saves as unified
# Check file was created (JSON by default)
db = test_db$methods,  # Just the methods portion
test_that("import/export functions handle errors gracefully", {
# Import should return empty list but succeed
result <- boilerplate_import(data_path = empty_data_dir, quiet = TRUE)
test_db <- list(methods = list(test = list(description = "Test")))
# Test save with invalid category - save doesn't validate category names
# so this should succeed but create a file with the invalid category name
test_that("boilerplate_export preserves database structure", {
# Create database with various data types
list_data = list(a = 1, b = "two", c = TRUE),
# Export with data_path and filename separately
test_that("boilerplate_import handles legacy database formats", {
# Create database in correct format (no wrapper)
# Save in expected format with correct filename
imported <- boilerplate_import(category = "methods", data_path = data_dir, quiet = TRUE)
# The imported data should match what we saved