This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
R package (talib) providing an interface to the TA-Lib C library for technical analysis indicators and candlestick pattern recognition. TA-Lib is vendored as a git submodule in src/ta-lib/.
make build # Full build: gen-code → document → install
make check # R CMD check --as-cran
make check-full # R CMD check with valgrind
make test # Run testthat suite
make fmt # Format code (air for R, clang-format for C)
make document # Regenerate roxygen2 documentation
make gen-code # Regenerate R wrappers, C wrappers, and tests from templates
make bench # Run performance benchmarksSingle test file: Rscript -e "testthat::test_file('tests/testthat/test-ta_APO.R')"
Most R wrappers (R/ta_*.R), C wrappers (src/ta_*.c), and tests (tests/testthat/test-ta_*.R) are auto-generated. Do not edit these directly — modify the generation infrastructure in codegen/ instead:
codegen/gen_code/indicators.R— Unified metadata for all 128 indicatorscodegen/gen_code/generate.R— Single driver script that generates R, C, and test filescodegen/gen_code/utils.R—impl_generate_indicator()andimpl_generate_test()helperscodegen/generate_indicator.sh,generate_API.sh,generate_FFI.sh— Shell scripts for template-driven generationsrc/api.handsrc/init.c— Auto-generated (function prototypes and R registration)
Run make gen-code after changing any generation logic.
Uses .Call() (R's native C interface), not Rcpp. Each indicator has:
- C wrapper (
src/ta_*.c): Converts R SEXP → C arrays, calls TA-Lib, returns SEXP matrix - R wrapper (
R/ta_*.R): S3 generic with methods fordefault,data.frame, andplotly
C memory management uses manual PROTECT/UNPROTECT with protection counters.
Every indicator follows this pattern:
indicator <- function(x, cols, ...) UseMethod("indicator")
indicator.default # Handles matrix/data input, calls .Call()
indicator.data.frame # Extracts columns via series(), delegates, re-wraps via map_dfr()
indicator.matrix # Forwards to .default without NextMethod()
indicator.numeric # Univariate fast path (single-column formulas only)
indicator.plotly # Adds indicator as plotly trace
indicator.ggplot # Adds indicator as ggplot2 layerColumn selection uses formula syntax: cols = ~close, cols = ~high + low.
Two rendering backends are selected via options(talib.chart.backend = ...):
"plotly"(default) — interactive HTML via{plotly}(Suggests)"ggplot2"— static output via{ggplot2}(Suggests)
chart() + indicator() share per-pipeline state stashed in the caller's
evaluation frame (key .talib_chart_state); .chart_state() in R/zzz.R
walks the call stack via sys.frame() / sys.nframe() to retrieve it.
This keeps parallel pipelines (Shiny, futures, nested function bodies)
isolated without depending on those packages. chart() and its
indicator() calls must live in the same enclosing frame.
R/chart.R—chart()entry point and plotly candlestick backendR/chart_ggplot.R— ggplot2 candlestick backend, theme, axis scalesR/chart_indicator.R—indicator()single/multi dispatch, panel assembly, print methodsR/chart_build.R— sharedbuild_plotly()/build_ggplot()used by generated wrappersR/chart_elements.R,R/chart_layout.R,R/chart_pattern.R— annotations, plotly layout decorators, candlestick pattern markersR/chart_theme.R— theme registry andset_theme()R/zzz.R—.onLoad/.onAttachhooks, per-pipeline state helpers, package-level.chart_variablestheme envR/series.R— Formula-based column selection logic (series()S3 generic)R/utils.R— Input validation (assert_column_names(),assert_formula(), …),candlestick_setting(),set_rownames()/map_dfr()S3 genericsR/helper.R— Operators (%nn%,%or%), chart helpers (plotly_init,plotly_line,ggplot_init,ggplot_line,modify_traces,add_idx,rebuild_formula)R/BTC.R,R/NVDA.R,R/SPY.R,R/ATOM.R— Built-in OHLCV datasets (docs only;.rdafiles indata/)R/talib-package.R—generate_returns_section()used at roxygen-render time byman-roxygen/returns.Rsrc/dataframe.c— Matrix↔data.frame conversion (map_dfr)src/container.h,src/shift.h,src/names.h— Shared C utilities
src/ta-lib/ is a git submodule compiled via CMake into a static library (libta-lib.a). The configure script handles detection/compilation. SystemRequirements: CMake.
- Naming: TA-Lib
TA_BBANDS()→ Rbollinger_bands()(snake_case), with uppercase aliasBBANDS - Data: Expects OHLCV columns named
open,high,low,close,volume(case-sensitive) - Style: Tidyverse style guide; R formatted with
air, C withclang-format - Docs: Roxygen2 with Markdown syntax; never edit
man/*.Rddirectly - Tests: testthat edition 3; auto-generated tests cover alias equivalence, type preservation, dimension integrity, and value correctness