inst/AGENTS.md

vectra — Notes for AI Coding Agents

vectra is a self-contained R columnar query engine (pure C11 backend) for larger-than-RAM data. It exposes dplyr-style verbs that build a lazy plan; the plan executes only when collect() is called. Sources include vectra's native .vtr format, CSV(.gz), SQLite, Excel (.xlsx), and GeoTIFF.

Core workflow

library(vectra)

# 1. Open a source -> lazy `vectra_node`
node <- tbl_csv("measurements.csv")

# 2. Compose verbs (still lazy)
q <- node |>
  filter(temperature > 30, year >= 2020) |>
  group_by(station) |>
  summarise(avg_temp = mean(temperature), n = n())

# 3. Execute
df <- collect(q)        # returns a data.frame
explain(q)              # inspect optimized plan without executing

Sources (all return a vectra_node)

Sinks

Star schemas

s <- vtr_schema(
  fact    = tbl("obs.vtr"),
  species = link("sp_id", tbl("species.vtr")),     # unnamed key = same name in both
  site    = link(c(site_id = "id"), tbl("sites.vtr"))  # named key = remap
)
lookup(s, value, species$name, site$habitat, .join = "left", .report = TRUE) |> collect()

link() and vtr_schema() accept only file-backed nodes (created by tbl() / tbl_csv() / tbl_sqlite()). Nodes that come out of verbs have no file path and will be rejected.

Indexes and materialized blocks

Out-of-core model fitting and per-group work

The engine streams, so a result larger than memory reduces to a summary in one pass, and per-group work splits into shards that each fit in memory.

# Streaming OLS: accumulate X'X and X'y in one pass, never holding the matrix
acc <- tbl("survey.vtr") |> select(mpg, wt, hp) |>
  collect_chunked(function(acc, chunk) {
    X <- cbind(1, chunk$wt, chunk$hp)
    list(XtX = acc$XtX + crossprod(X), Xty = acc$Xty + crossprod(X, chunk$mpg))
  }, .init = list(XtX = matrix(0, 3, 3), Xty = matrix(0, 3, 1)))
solve(acc$XtX, acc$Xty)

# Out-of-core GLM: prepare once, then bigglm re-reads the spill on every pass
s <- offload(tbl("occ.vtr") |> select(presence, bio1, bio12))
biglm::bigglm(presence ~ bio1 + bio12, data = chunk_feeder(s), family = binomial())

# Per-key shards: group_map runs any function on each in-memory shard (here a GLM)
p <- offload(tbl("occ.vtr"), by = "region")
fits <- group_map(p, function(d, region)
  glm(presence ~ bio1 + bio12, data = d, family = binomial()))

Constraints and common mistakes

Use cases / keywords

ETL across CSV/SQLite/TIFF/.vtr; out-of-core dplyr; star-schema lookups; streaming aggregations; out-of-core OLS/GLM fitting (collect_chunked and chunk_feeder + biglm); per-key sharding for any per-group function (offload(by=) + group_map); hash + zone-map predicate pushdown; fuzzy string matching (Levenshtein / Damerau-Levenshtein / Jaro-Winkler) inside the engine; GeoTIFF point sampling without terra; integer raster output with quantization and spatial predictor encoding.



Try the vectra package in your browser

Any scripts or data that you put into this service are public.

vectra documentation built on July 10, 2026, 5:08 p.m.