2  Building Pipelines with T

2.1 Learning Outcomes

By the end of this chapter, you will:

  • Understand the difference between environment reproducibility and computational reproducibility.
  • Understand the core concepts of T: pipelines, nodes, runtimes, and serialization contracts.
  • Write multi-language pipelines combining Python and R using pyn() and rn().
  • Pass structured data across languages seamlessly with Apache Arrow IPC (^ipc).
  • Understand how T discovers data dependencies and uses content-addressed caching to skip redundant computations.

2.2 Introduction: Beyond Environment Reproducibility

In the previous chapter, we explored Nix and learned how to create bit-for-bit reproducible development environments. But here is a critical reality:

Reproducing the environment is necessary, but it is not sufficient.

Imagine a colleague sends you a GitHub repository. Thanks to Nix, you drop into the exact software environment in seconds. You have R 4.4.1, Python 3.13, and all libraries installed. But when you open the repository, you find:

01_clean.R
02_process.py
analysis_v2.R
test_model.py
run_everything.sh
clean_data_final.csv

Which script runs first? Which outputs feed into which inputs? Did the author run 02_process.py before analysis_v2.R, or did they manually run snippets in an interactive session? Is clean_data_final.csv up to date, or was it produced three months ago from an older version of 01_clean.R?

Reproducing the environment only solves the first half of the problem. To achieve computational reproducibility, the workflow itself must be formally declared in a machine-readable graph.

This is where T (tlang) comes in.

2.3 A First Look at a T Pipeline

2.3.1 Getting Started: An Ephemeral Nix Shell

Before writing or running a pipeline, how do you actually get T on your computer?

Because you already installed and configured Nix in Chapter 2, you do not need to install T globally, download binaries manually, or compile anything from source. Instead, you can run T immediately in a temporary (ephemeral) shell directly from its GitHub repository:

nix shell --accept-flake-config github:b-rodrigues/tlang

This single command:

  1. Fetches the pinned T flake from the b-rodrigues/tlang GitHub repository.
  2. Pulls the pre-compiled T binary directly from the rstats-on-nix Cachix substituter configured in the previous chapter.
  3. Drops you into an isolated subshell where the t CLI binary is immediately available on your $PATH.
  4. Leaves no permanent clutter on your system: as soon as you type exit, your shell reverts to normal.

2.3.1.1 Testing the Setup and the REPL

While inside this temporary shell, you can immediately test that T is functioning properly by launching its built-in interactive demo:

t demo

This terminal demo showcases pipeline DAG construction, hermetic Nix builds, Arrow in-memory inspection, and content-addressed caching in real time.

You can also start an interactive Read-Eval-Print Loop (REPL) to explore T expressions:

t repl

(or simply run t).

2.3.1.2 Scaffolding a New Project

The t CLI includes built-in project scaffolding. While inside your temporary shell, you can scaffold a new reproducible analysis workspace:

t init --project my_project

The tool will prompt you with a few configuration questions (project name, author, license, pipeline template preference, etc.) and generate a standard directory layout:

  • src/pipeline.t: Your main analysis pipeline file, containing a working template with sample nodes.
  • tproject.toml: The declarative manifest where you configure required R, Python, and Julia packages.
  • flake.nix: A pinned Nix environment definition locking all dependencies deterministically across Linux and macOS.
  • AGENTS.md and T-LANGUAGE-REFERENCE.md: Context files so AI coding assistants (such as Claude Code, GitHub Copilot, or Antigravity) understand T grammar immediately.
  • .envrc: Integration with direnv so your development environment activates automatically upon entering the folder.

2.3.1.3 Entering Your Project’s Environment

Once the project is scaffolded, exit the temporary nix shell by typing exit. Move into your new project directory and enter its dedicated, reproducible development environment:

cd my_project
nix develop

Inside this development shell, the t executable is available alongside all your declared language runtimes (R, Python, and Julia). You can execute your entire pipeline from end to end using:

t run src/pipeline.t

2.3.2 An End-to-End Pipeline Example

Now that you know how to access T and bootstrap a workspace, let us examine an end-to-end polyglot pipeline in T:

p = pipeline {
  -- 1. Ingest raw CSV data (serialize as Arrow IPC for downstream nodes)
  data = node(
    command = read_csv("datasets/housing_data.csv"),
    serializer = ^ipc
  )

  -- 2. Python node: Feature engineering
  cleaned_py = pyn(
    command = <{
import pandas as pd

# Filter positive prices and calculate price per square meter
cleaned_py = data[data["price"] > 0].copy()
cleaned_py["price_sqm"] = cleaned_py["price"] / cleaned_py["surface"]
cleaned_py
    }>,
    deserializer = ^ipc,
    serializer = ^ipc
  )

  -- 3. R node: Statistical analysis and visualization
  plot_r = rn(
    command = <{
library(ggplot2)
library(dplyr)

plot_r <- ggplot(cleaned_py, aes(x = surface, y = price)) +
  geom_point(alpha = 0.5, color = "steelblue") +
  geom_smooth(method = "lm", color = "darkred") +
  theme_minimal() +
  labs(
    title = "Housing Prices in Luxembourg",
    x = "Surface (m²)",
    y = "Price (€)"
  )
    }>,
    deserializer = ^ipc
  )
}

build_pipeline(p)

Notice what just happened: 1. data loads raw data. 2. cleaned_py runs in Python using pandas. It receives data as an Apache Arrow table via deserializer = ^ipc, computes new columns, and serializes its output with serializer = ^ipc. 3. plot_r runs in R using {ggplot2}. It receives cleaned_py directly from Python without you writing a single line of CSV export/import glue code! 4. build_pipeline(p) builds every node in dependency order and caches the results.

2.4 Anatomy of a T Pipeline

Let us break down the core components of T.

2.4.1 1. The pipeline { ... } Block

A pipeline is defined using a declarative block:

p = pipeline {
  node_a = ...
  node_b = ...
}

The code inside the braces is purely declarative: it defines a Directed Acyclic Graph (DAG). Nothing runs when you assign p. The pipeline is a first-class object that you can inspect, pass to functions, or compile.

2.4.2 2. Nodes: Pure Computations

Each named entry in a pipeline is a node. A node represents a single unit of computation that produces a single artifact. T provides runtime-specific constructors:

  • pyn(...): Declares a Python node.
  • rn(...): Declares an R node.
  • jln(...): Declares a Julia node.
  • cmd(...): Declares an external shell/command-line execution.
  • node(...): Generic node constructor where you explicitly pass runtime = R, runtime = Python, etc.

The code to execute is passed in the command argument using <{ ... }> delimiters. T does not interpret this code; it sends it to the language runtime to execute inside a hermetic Nix sandbox.

2.4.3 3. Automatic Dependency Resolution

Notice that in our example, we never explicitly told plot_r that it depends on cleaned_py.

T automatically scans the code inside <{ ... }> for references to upstream node names. Because the R code references cleaned_py, T draws a directed edge:

\[\text{data} \longrightarrow \text{cleaned\_py} \longrightarrow \text{plot\_r}\]

Because dependencies are inferred from names, the order in which you write nodes inside pipeline { ... } does not matter. T topological-sorts the graph and executes nodes in their true mathematical dependency order.

2.4.4 4. Zero-Glue Serialization with Apache Arrow (^ipc)

Passing data between different languages has historically been one of the biggest headaches in data science. Exporting intermediate CSVs causes problems: - Numbers lose precision. - Timestamps and dates lose timezones. - Categories and factors become raw strings. - Disk I/O is slow for large datasets.

T solves this with typed serialization symbols:

  • ^ipc: Apache Arrow IPC (Inter-Process Communication). This is an in-memory, binary columnar format shared by R, Python, and Julia. When Python writes ^ipc and R reads ^ipc, the data is transferred with exact type preservation and zero friction.
  • ^csv: Standard comma-separated values.
  • ^parquet: Columnar compressed storage (ideal for larger datasets).
  • ^rds: Native R object serialization.
  • ^pickle: Native Python object serialization.

2.4.5 5. Executing and Inspecting Pipelines

To execute a pipeline, call build_pipeline(p):

build_pipeline(p)

T inspects each node in the DAG: 1. Has this node ever been built? 2. Have any of its upstream inputs changed? 3. Has the code inside its command block changed?

If the answer to all three is “no”, T retrieves the existing artifact from cache in microseconds. If any input has changed, only that node and its downstream dependents are rebuilt.

To inspect the result of any node interactively, use read_node():

result = read_node(p.cleaned_py)

2.5 Using External Functions

While embedding short snippets inside <{ ... }> is convenient for small steps, realistic projects organize logic into external source files. T makes this straightforward:

p = pipeline {
  coords = rn(
    command = <{
      coords <- clean_coordinates(raw_data)
    }>,
    functions = ["src/cleaning.R"],
    deserializer = ^ipc,
    serializer = ^ipc
  )
}

The functions argument automatically sources src/cleaning.R into the R session before running the node’s command. Similarly, Python nodes can import modules placed in src/.

If your node needs external files (such as raw images, reference tables, or configuration YAMLs), specify them with include:

model = pyn(
  command = <{
    # Train model using config
  }>,
  include = ["config/model_params.yaml"]
)

2.6 Hands-On Exercise: Build Your First Pipeline with an AI Agent

Now that you understand the core mechanics of T pipelines, nodes, and Arrow IPC serialization, it is time to build one yourself!

Modern reproducible workflows are built in collaboration with AI coding assistants (such as Antigravity, Claude Code, GitHub Copilot, or Cursor). T was specifically designed for this paradigm: when you scaffold a project, it automatically provisions context files so your AI assistant writes syntactically valid, idiomatic T from day one.

In this exercise, you will pair with your AI agent to bootstrap a project, create a toy dataset, construct a polyglot pipeline that performs basic data manipulation, and verify DAG caching.

2.6.1 Step 1: Bootstrap the Workspace

Prompt your AI assistant (or execute the commands yourself in your terminal):

“Launch a temporary Nix shell using nix shell --accept-flake-config github:b-rodrigues/tlang and initialize a new T project called toy_pipeline using t init --project toy_pipeline. Select the full pipeline template and the default Nixpkgs date.”

Once the project is scaffolded, exit the temporary shell (exit), enter the directory, and drop into its pinned development environment:

cd toy_pipeline
nix develop
TipThe Built-in AI Harness

Notice that t init created two key files in your project root: AGENTS.md and T-LANGUAGE-REFERENCE.md. These files inform your AI coding assistant about T’s syntax, node constructors (pyn, rn, jln), and serialization conventions (^ipc). When your agent has access to these files in its workspace, it produces accurate code without hallucinating syntax.

2.6.2 Step 2: Create a Toy Dataset

Ask your agent to generate a small toy dataset inside data/:

“Create a CSV file at data/students.csv with 6 rows containing columns name, score (integer out of 100), and attendance (float between 0.0 and 1.0).”

For example:

name,score,attendance
Alice,85,0.95
Bob,52,0.70
Charlie,91,0.98
Diana,48,0.65
Ethan,74,0.88
Fiona,63,0.75

2.6.3 Step 3: Prompt Your Agent to Write the Pipeline

Now, give your AI assistant a clear prompt to author the pipeline in src/pipeline.t:

“In src/pipeline.t, write a pipeline named p that: 1. Reads data/students.csv into a node named raw_data using node(command = read_csv(\"data/students.csv\"), serializer = ^ipc). 2. Defines a Python node clean_py using pyn() that: - Ingests raw_data with deserializer = ^ipc. - Filters for students with attendance >= 0.70. - Adds a new column adjusted_score = score * 1.05. - Adds a boolean column passed = adjusted_score >= 60. - Ends the block with the resulting DataFrame and serializes it with serializer = ^ipc. 3. Defines an R node summary_r using rn() that: - Ingests clean_py with deserializer = ^ipc. - Uses {dplyr} to calculate average adjusted_score grouped by passed. - Serializes the summary with serializer = ^ipc. 4. Executes the pipeline with build_pipeline(p) and prints read_node(p.clean_py) and read_node(p.summary_r).”

2.6.4 Step 4: Run, Inspect, and Verify Caching

Run the pipeline from your project shell:

t run src/pipeline.t

If t detects missing packages in tproject.toml (such as pandas, pyarrow, arrow, dplyr, or jsonlite), confirm the prompt (y) so t adds them and builds the node environments. You will then see T resolve the DAG, materialize the Apache Arrow IPC buffers, and print the outputs.

Now test the caching behavior of T:

  1. Inspect inside T: Notice how read_node(p.clean_py) and read_node(p.summary_r) use dot access on p (you can also run these expressions interactively in t repl once p is defined).

  2. Observe Instant Caching: Re-run the pipeline immediately without changing any files:

    t run src/pipeline.t

    Notice that T prints All nodes were already cached — nothing to build. and finishes immediately!

  3. Test Invalidation: Edit a score in data/students.csv and re-run t run src/pipeline.t. Observe how T detects the updated input and recomputes the pipeline with the new score.

2.7 Summary

T shifts your workflow from writing imperative, error-prone scripts to declaring a deterministic DAG of computations. In the next chapter, we will examine the theoretical foundation that makes this work: why treating pipeline nodes as pure functions unlocks effortless caching and rock-solid reproducibility.