Skip to content

Conversation

@PavelMakarchuk
Copy link
Collaborator

Summary

Adds an R package (policyenginetaxsim) that allows R users to run the PolicyEngine TAXSIM emulator directly from R.

Closes #690

Changes

  • New r-package/policyenginetaxsim/ directory containing the R package
  • Uses reticulate to bridge R and Python
  • Automatically sets up Python environment (Miniconda) if needed

Functions

Function Purpose
policyengine_calculate_taxes() Calculate taxes for tax units
setup_policyengine() One-time Python environment setup
check_policyengine_setup() Verify setup is complete
compare_with_taxsim() Compare with NBER TAXSIM (via usincometaxes)
summary_comparison() Get comparison statistics

Usage

# Install
devtools::install_github("PolicyEngine/policyengine-taxsim",
                          subdir = "r-package/policyenginetaxsim")

# Setup (one time, ~5-10 min)
library(policyenginetaxsim)
setup_policyengine()

# Calculate taxes
my_data <- read.csv("household_data.csv")
results <- policyengine_calculate_taxes(my_data)

# Compare with TAXSIM
comparison <- compare_with_taxsim(my_data)

Testing

  • Verified R package produces identical output to Python emulator
  • Tested across 15 diverse scenarios (various income levels, states, filing statuses, income types)
  • All 32 output columns match with <$0.01 difference (floating point rounding only)

Test Plan

  • Test on fresh Mac without Python
  • Test on Windows
  • Test on Linux
  • Test with large datasets (1000+ records)

🤖 Generated with Claude Code

PavelMakarchuk and others added 6 commits January 4, 2026 14:30
- Add policyenginetaxsim R package using reticulate for Python bridge
- Implement policyengine_calculate_taxes() for tax calculations
- Implement setup_policyengine() for automated Python environment setup
- Implement compare_with_taxsim() for side-by-side comparison with NBER TAXSIM
- Support TAXSIM-compatible input/output format
- Auto-install Miniconda if no Python available
- Tested: R package produces identical output to Python emulator

Closes #690

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Fix TaxsimRunner to find executable from any directory (not just repo root)
- Search multiple paths: relative, sys.prefix, sys.base_prefix for installed packages
- Update R package compare_with_taxsim() to use embedded taxsimtest executable
- Remove dependency on usincometaxes package for comparison
- Verified: R package produces identical output to Python emulator (2022-2024)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Remove usincometaxes dependency from comparison docs
- Update example output to show exact match ($0 diff)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Remove detailed input/output variable tables
- Point to TAXSIM 35 documentation for full variable list
- Note that state codes accept both numbers and abbreviations

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@PavelMakarchuk PavelMakarchuk marked this pull request as ready for review January 4, 2026 20:45
@PavelMakarchuk PavelMakarchuk merged commit 5da8911 into main Jan 4, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add R package wrapper for PolicyEngine TAXSIM emulator

2 participants