Skip to contents

CORE AST EXECUTION: This function now uses Abstract Syntax Tree (AST) evaluation as its fundamental execution engine. All pending steps are processed through the AST system for optimized, validated, and traceable execution.

Usage

bake_steps(svy)

Arguments

svy

A Survey or RotativePanelSurvey object with pending steps to execute

Value

The same type of object as input with all transformations materialized in the data and the step history updated to reflect completed operations

Details

AST CORE EXECUTION ENGINE:

1. AST Step Processing:

  • All pending steps converted to AST representation

  • Dependency graphs built from AST analysis

  • Execution order optimized based on dependencies

  • Each step validated before materialization

2. Enhanced Execution Features:

  • AST optimization applied to all expressions

  • Parallel dependency resolution where possible

  • Advanced error detection with precise context

  • Comprehensive execution logging and traceability

3. Performance Benefits:

  • Pre-compiled AST expressions for faster execution

  • Optimized evaluation paths reduce computation time

  • Cached intermediate results for repeated operations

  • Minimal memory overhead with maximum performance gains

4. AST Capabilities:

  • Automatic dependency validation prevents runtime errors

  • Expression optimization (constant folding, dead code elimination)

  • Better error messages with step and expression context

  • Comprehensive audit trail of all transformations

The function provides several key advantages through AST:

  • AST Optimization: All expressions optimized before execution

  • Dependency Validation: Variables verified to exist using AST analysis

  • Error Prevention: Static analysis catches errors before runtime

  • Performance: Optimized execution paths and cached compilations

  • Traceability: Complete AST-based audit trail of transformations

  • Complex Handling: RotativePanelSurvey processed with AST at all levels

For RotativePanelSurvey objects, the AST engine processes both the implantation level and follow-up levels, applying appropriate AST optimizations according to the level specified in each step.

Steps are executed in dependency-optimized order determined by AST analysis, and each step's AST expressions can reference variables created by previous steps.

Examples

if (FALSE) { # \dontrun{
# Basic AST execution with Survey
ech <- load_survey("ech_2023.dta", svy_type = "ech", svy_edition = "2023") |>
  step_compute(
    employed = ifelse(POBPCOAC == 2, 1, 0),
    optimize_ast = TRUE,  # AST optimization enabled
    comment = "Employment indicator - AST optimized"
  ) |>
  step_recode(
    age_group,
    e27 < 18 ~ "Minor",              # AST validates e27 exists
    e27 >= 18 & e27 < 65 ~ "Adult",  # AST optimizes conditions
    e27 >= 65 ~ "Senior",
    validate_deps = TRUE,  # AST dependency validation
    comment = "Age groups - AST powered"
  )

# Execute all steps with AST engine
processed_ech <- bake_steps(ech)  # AST processes all steps optimally

# Verify AST-created variables exist  
print(names(processed_ech$data))

# AST RotativePanelSurvey execution
panel <- load_panel_survey("panel_2023.dta") |>
  step_compute(
    # AST optimizes: 100 * 1.0 → 100
    activity_rate = active / population_14_plus * 100 * 1.0,
    .level = "quarter",
    optimize_ast = TRUE,
    comment = "Quarterly activity rate - AST optimized"
  )

processed_panel <- bake_steps(panel)  # AST handles multi-level execution

# AST-optimized pipeline with recipes  
result <- load_survey("data.dta", 
                     svy_type = "ech", 
                     svy_edition = "2023",
                     recipes = my_ast_recipe) |>
  bake_steps()  # Apply recipe with AST
} # }