# Create a temporary directory and initialise databases
temp_dir <- tempdir()
data_path <- file.path(temp_dir, "boilerplate_text_example", "data")
# Initialise with default content
boilerplate_init(
categories = c("methods", "results"),
data_path = data_path,
create_dirs = TRUE,
create_empty = FALSE,
confirm = FALSE,
quiet = TRUE
)
# Import the databases
unified_db <- boilerplate_import(data_path = data_path, quiet = TRUE)
# Basic usage with methods sections
methods_text <- boilerplate_generate_text(
category = "methods",
sections = c("sample"),
global_vars = list(
exposure_var = "political_conservative",
population = "university students",
timeframe = "2023-2024"
),
db = unified_db,
quiet = TRUE
)
# Check the output
cat(substr(methods_text, 1, 100), "...\n")
# Using with headings
methods_text <- boilerplate_generate_text(
category = "methods",
sections = c("sample"),
global_vars = list(
exposure_var = "treatment",
timeframe = "2023-2024"
),
db = unified_db,
add_headings = TRUE,
heading_level = "##",
quiet = TRUE
)
# Clean up
unlink(file.path(temp_dir, "boilerplate_text_example"), recursive = TRUE)
Run the code above in your browser using DataLab