### Initialize Tidy Graph Examples Source: https://github.com/jtmenchaca/tidy-ts/blob/main/packages/examples/dataframe/tidy-graph-examples.ipynb Imports necessary functions from @tidy-ts/dataframe and logs a readiness message. This is a setup step for the examples. ```python import { createDataFrame, type DataFrame, stats } from "@tidy-ts/dataframe"; console.log("📊 Tidy Graph Examples - Ready to visualize!"); ``` -------------------------------- ### Verify pnpm Workspace Setup Source: https://github.com/jtmenchaca/tidy-ts/blob/main/repo-setup.md Lists the top-level packages installed in the pnpm workspace to verify the setup. ```bash pnpm list --depth=0 ``` -------------------------------- ### Complete Browser Setup with HTML Source: https://github.com/jtmenchaca/tidy-ts/blob/main/docs/api/dataframe/setup.md A full HTML example demonstrating how to set up tidy-ts in a browser environment using import maps and an async main function to initialize WASM before using DataFrame and stats functions. ```html ``` -------------------------------- ### Setup for Windows Cross-Compilation on macOS Source: https://github.com/jtmenchaca/tidy-ts/blob/main/repo-setup.md Install the necessary Rust target and the cargo-xwin tool for cross-compiling Windows binaries from a macOS environment. This is a one-time setup. ```bash rustup target add x86_64-pc-windows-msvc cargo install cargo-xwin ``` -------------------------------- ### Browser Setup for Tidy-TS Source: https://github.com/jtmenchaca/tidy-ts/blob/main/README.md In browser environments, call setupTidyTS() once at application startup before using any tidy-ts functions. This example shows the necessary import and setup call. ```typescript import { setupTidyTS, createDataFrame, stats } from "@tidy-ts/dataframe"; // Required in browsers - call once at app startup await setupTidyTS(); ``` -------------------------------- ### Install Dependencies Source: https://github.com/jtmenchaca/tidy-ts/blob/main/packages/docs/README.md Installs project dependencies using Bun. ```bash bun install ``` -------------------------------- ### Start Development Server Source: https://github.com/jtmenchaca/tidy-ts/blob/main/packages/docs/README.md Starts the development server for Tidy-TS. ```bash bun run dev ``` -------------------------------- ### Browser Setup and Usage Source: https://github.com/jtmenchaca/tidy-ts/blob/main/docs/api/dataframe/setup.md Demonstrates the essential browser setup by calling setupTidyTS once before using statistical functions. It then shows creating a DataFrame and calculating its mean. ```typescript import { setupTidyTS, createDataFrame, stats as s } from "@tidy-ts/dataframe"; // Initialize WASM (required in browsers, no-op elsewhere) await setupTidyTS(); // Now you can use all tidy-ts features const df = createDataFrame([{ x: 1 }, { x: 2 }, { x: 3 }]); const meanValue = s.mean(df.x); ``` -------------------------------- ### Install MCP Server Globally Source: https://github.com/jtmenchaca/tidy-ts/blob/main/packages/mcp/README.md Installs the Tidy-TS MCP server globally on your system, making the `tidy-ts-mcp` command available everywhere. This is a one-time setup step. ```bash pnpm mcp:install ``` ```bash deno install --global -A --name tidy-ts-mcp --force packages/mcp/cli.ts ``` -------------------------------- ### Python Statistical Analysis Setup Source: https://github.com/jtmenchaca/tidy-ts/blob/main/docs/JAMIA/ai-blueprint/papers/2025-02/https___pmc.ncbi.nlm.nih.gov_articles_PMC11756633_/Ambient-artificial-intelligence-scribes-utilization-and-impact-on-documentation-.md This snippet shows the setup for statistical analysis using the statsmodels package in Python. Ensure Python version 3.11.4 or compatible is installed. ```python import statsmodels.api as sm import pandas as pd import numpy as np ``` -------------------------------- ### Run Descriptive Agent Evaluation Example Source: https://github.com/jtmenchaca/tidy-ts/blob/main/docs/JAMIA/compile-time-safety/comparisons/agent-evaluation/CONTEXT.md Manually run the descriptive agent evaluation example from the repository root. Ensure you have your OpenAI API key set. ```bash OPENAI_API_KEY=sk-... deno run -A \ docs/JAMIA/comparisons/agent-evaluation/examples/descriptive.ts ``` -------------------------------- ### Quick Start: Create and Analyze Sales Data Source: https://github.com/jtmenchaca/tidy-ts/blob/main/README.md This example demonstrates creating a DataFrame from row objects, performing data analysis including adding new columns, grouping, summarizing, and arranging the results. It uses the stats object for aggregation functions. ```typescript import { createDataFrame, stats as s } from "@tidy-ts/dataframe"; // Create DataFrame from rows const sales = createDataFrame([ { region: "North", product: "Widget", quantity: 10, price: 100 }, { region: "South", product: "Widget", quantity: 20, price: 100 }, { region: "East", product: "Widget", quantity: 8, price: 100 }, ]); // Complete data analysis workflow const analysis = sales .mutate({ revenue: (row) => row.quantity * row.price, moreThanAvg: (row, _index, df) => row.quantity > s.mean(df.quantity) }) .groupBy("region") .summarize({ total_revenue: (group) => s.sum(group.revenue), avg_quantity: (group) => s.mean(group.quantity), product_count: (group) => group.nrows() }) .arrange("total_revenue", "desc"); analysis.print("Sales Analysis"); ``` -------------------------------- ### Install OpenAI Libraries Source: https://github.com/jtmenchaca/tidy-ts/blob/main/dbmi_workshop.ipynb Installs the necessary openai and openai-agents libraries for Python. Run this cell first to set up your environment. ```python %pip install -q openai openai-agents ``` -------------------------------- ### Run Quick Start Benchmarks Source: https://github.com/jtmenchaca/tidy-ts/blob/main/packages/testing/benchmarks/README.md Execute the stable benchmark for tidy-ts and its Polars comparison. This is a quick way to get performance metrics on smaller datasets (100K + 500K rows). ```bash # Run the stable benchmark (tidy-ts operations, 100K + 500K rows) deno run -A --no-check packages/testing/benchmarks/bench-stable.ts # Run matching Polars comparison python3 packages/testing/benchmarks/bench-npm-polars.py # Run the full cross-language benchmark suite (TS + Python + R) cd packages/testing/benchmarks deno run -A runner.ts # Analyze results and generate comparison table deno run -A analyze.ts ``` -------------------------------- ### React/Vite App Initialization Setup Source: https://github.com/jtmenchaca/tidy-ts/blob/main/docs/api/dataframe/setup.md Shows how to integrate tidy-ts setup into a React application's initialization using useEffect to ensure the WASM module is loaded before rendering stats-dependent components. ```javascript import { useEffect, useState } from "react"; import { setupTidyTS, createDataFrame, stats as s } from "@tidy-ts/dataframe"; function App() { const [ready, setReady] = useState(false); useEffect(() => { setupTidyTS().then(() => setReady(true)); }, []); if (!ready) return
Loading...
; // Now safe to use tidy-ts stats functions const df = createDataFrame([{ value: 10 }, { value: 20 }]); return
Mean: {s.mean(df.value)}
; } ``` -------------------------------- ### Install Deno and Jupyter Kernel Source: https://github.com/jtmenchaca/tidy-ts/blob/main/dbmi_workshop-ts-v2.ipynb Installs the Deno runtime and registers it as a Jupyter kernel for use in environments like Google Colab. After running, change the runtime type to Deno. ```python !curl -fsSL https://deno.land/install.sh | DENO_INSTALL=/usr/local sh -s -- -y !deno jupyter --install print("Deno kernel installed. Now switch the runtime: Runtime → Change runtime type → Deno.") ``` -------------------------------- ### LinearBackoff Configuration Example Source: https://github.com/jtmenchaca/tidy-ts/blob/main/docs/api/shims/async.md Example of configuring a LinearBackoff strategy with custom maxRetries and baseDelay. This strategy provides consistent delay growth between retries. ```typescript import type { LinearBackoff } from "@tidy-ts/shims"; // Linear: 100ms, 200ms, 300ms, 400ms... const config: LinearBackoff = { backoff: "linear", maxRetries: 5, baseDelay: 100, }; ``` -------------------------------- ### Initialize Repository Structure Source: https://github.com/jtmenchaca/tidy-ts/blob/main/repo-setup.md Basic commands to create a new project directory and initialize it as a Git repository. ```bash mkdir your-project cd your-project git init ``` -------------------------------- ### Root and Package package.json Example Source: https://github.com/jtmenchaca/tidy-ts/blob/main/repo-setup.md Illustrates how the root package.json defines actual dependency versions while package-level package.json files use wildcards resolved by pnpm overrides. ```json // Root package.json { "dependencies": { "react": "^19.1.1", "zod": "^4.1.12" } } // packages/frontend/package.json { "dependencies": { "react": "*", "zod": "*" } } ``` -------------------------------- ### Quick Reference: Build and Publish Commands Source: https://github.com/jtmenchaca/tidy-ts/blob/main/repo-setup.md Common commands for version bumping, building Rust and JS artifacts, and publishing to JSR and npm registries. ```bash pnpm bump 1.4.1 # Update version in all 12 files pnpm build # Rust → WASM + native addons + npm JS bundles pnpm publish:all:jsr # JSR (deno publish for dataframe, shims, arrow, parquet, ai) pnpm publish:all:npm # npm (publishes shims, native addons, dataframe from pre-built dist/) ``` -------------------------------- ### Install Tidy-TS DataFrame Package Source: https://github.com/jtmenchaca/tidy-ts/blob/main/repo-setup.md Installs the Tidy-TS DataFrame package using npm. No special .npmrc configuration is required for installation. ```bash npm install @tidy-ts/dataframe ``` -------------------------------- ### GET Request with tidyfetch Source: https://github.com/jtmenchaca/tidy-ts/blob/main/docs/api/shims/fetch.md Use for readable GET requests. This snippet demonstrates a basic GET request to fetch user data. ```typescript import { tidyfetch } from "@tidy-ts/shims"; // GET request const result = await tidyfetch.get({ url: "/api/users", query: { limit: 10, offset: 0 } }); ``` -------------------------------- ### Test Validation for Examples Source: https://github.com/jtmenchaca/tidy-ts/blob/main/packages/docs/src/routes/general-approach.md Tests using Bun test framework to validate example functionality and type safety, mirroring examples from .examples.ts files. ```typescript import { describe, it, expect } from "bun:test"; import { createDataFrame, type DataFrame } from "@tidy-ts/dataframe"; describe("Topic Name", () => { it("should handle basic example correctly", () => { // Replicate the example code const df = createDataFrame([...]); // Type check const _typeCheck: DataFrame<{...}> = df; void _typeCheck; // Test functionality expect(df.nrows()).toBe(expected); expect(df.columns()).toEqual([...]); }); }); ``` -------------------------------- ### Create Root package.json Source: https://github.com/jtmenchaca/tidy-ts/blob/main/repo-setup.md Example of a root package.json file for a monorepo, including scripts, dependencies, and devDependencies. ```json { "name": "your-project", "version": "0.1.0", "private": true, "scripts": { "dev": "pnpm --filter @project/frontend dev & pnpm --filter @project/api dev", "fmt": "deno fmt .", "lint": "deno lint .", "check": "deno check ." }, "dependencies": { // Add all your actual dependencies with versions here "react": "^19.1.1", "zod": "^4.1.12" }, "devDependencies": { "typescript": "^5.9.3" } } ``` -------------------------------- ### Error Handling for WASM Loading Source: https://github.com/jtmenchaca/tidy-ts/blob/main/docs/api/dataframe/setup.md Demonstrates how to implement error handling using a try-catch block when calling setupTidyTS to gracefully manage potential failures during WebAssembly module loading. ```javascript try { await setupTidyTS(); } catch (error) { console.error("Failed to load WASM:", error); // Fallback: some operations work without WASM } ``` -------------------------------- ### Install Shims via npm Source: https://github.com/jtmenchaca/tidy-ts/blob/main/packages/shims/README.md Install the @tidy-ts/shims package using npm for Node.js or Bun. ```bash npm install @tidy-ts/shims ``` -------------------------------- ### Install Tidy-TS Dataframe Source: https://github.com/jtmenchaca/tidy-ts/blob/main/packages/dataframe/README.md Install the Tidy-TS DataFrame package using various package managers. ```bash deno add jsr:@tidy-ts/dataframe bunx jsr add @tidy-ts/dataframe pnpm add jsr:@tidy-ts/dataframe npx jsr add @tidy-ts/dataframe yarn add jsr:@tidy-ts/dataframe ``` -------------------------------- ### tidyfetch.get Source: https://github.com/jtmenchaca/tidy-ts/blob/main/docs/api/shims/fetch.md A shortcut for making GET requests. It functions identically to tidyfetch but with the method set to 'GET' by default. ```APIDOC ## tidyfetch.get ### Description A shortcut for making GET requests. It functions identically to tidyfetch but with the method set to 'GET' by default. ### Signature ```typescript tidyfetch.get(options: FetchOptions): Promise> ``` ### Import ```typescript import { tidyfetch } from "@tidy-ts/shims"; ``` ### Parameters - options: All tidyfetch options except method ``` -------------------------------- ### Create and Run a Basic AI Agent Source: https://github.com/jtmenchaca/tidy-ts/blob/main/dbmi_workshop-ts-v2.ipynb Instantiate an agent with a name, instructions, and model. Then, run the agent with a prompt and log the final output. ```typescript const agent = new Agent({ name: "Assistant", instructions: "You are a helpful assistant.", model: "gpt-5.4-mini", }); const result = await run(agent, "Write a haiku about a great AI workshop."); console.log(result.finalOutput); ``` -------------------------------- ### Get Current Directory Name Source: https://github.com/jtmenchaca/tidy-ts/blob/main/docs/api/shims/path.md Use to get the directory name of the current file using import.meta.url. ```typescript import { dirname, fileURLToPath } from "@tidy-ts/shims"; const __dirname = dirname(fileURLToPath(import.meta.url)); ``` -------------------------------- ### TTE Workflow Steps and Corresponding Packages Source: https://github.com/jtmenchaca/tidy-ts/blob/main/packages/dataframe/causal-inference-packages.md This outlines the typical steps in a Target Trial Emulation analysis and the R packages commonly used at each stage. ```text Step 1: Define eligibility & create person-time data └─ TrialEmulation::data_preparation() (sequential trial expansion) Step 2: Estimate propensity scores └─ WeightIt::weightit() or PSweight (for PS estimation) └─ TrialEmulation (uses internal GLM for IP weights) Step 3: Compute IPTW / IPCW └─ TrialEmulation (treatment + censoring weights) └─ WeightIt::weightitMSM() (for longitudinal weights outside TTE framework) Step 4: Assess covariate balance └─ cobalt::bal.tab() + cobalt::love.plot() └─ PSweight::SumStat() Step 5: Fit outcome model └─ TrialEmulation::trial_msm() (pooled logistic MSM) └─ survival::coxph() with weights (weighted Cox) └─ lmtp::lmtp_tmle() / lmtp::lmtp_sdr() (non-parametric, doubly robust) Step 6: Estimate causal effects └─ TrialEmulation::predict.TE_msm() (marginal risk differences, cumulative incidence) └─ lmtp (risk differences via TMLE/SDR) └─ PSweight::PSweight() (ATE/ATT/ATO with augmented estimators) Step 7: Sensitivity & diagnostics └─ debiasedTrialEmulation (negative control outcome calibration) └─ survival::cox.zph() (PH assumption) └─ cobalt (post-weighting balance) ``` -------------------------------- ### Build and Prerender Documentation Source: https://github.com/jtmenchaca/tidy-ts/blob/main/packages/docs/README.md Builds the Tidy-TS project and then prerenders all routes to static HTML files. ```bash bun run build bun run prerender ``` -------------------------------- ### Get, Set, Delete, and Load Environment Variables Source: https://github.com/jtmenchaca/tidy-ts/blob/main/docs/api/shims/env.md Demonstrates various ways to manage environment variables, including getting, setting, deleting, and loading from .env files. Use get() for reading, set() for temporary modifications, and loadFromFile() at application startup. ```typescript import { env } from "@tidy-ts/shims"; const apiKey = env.get("API_KEY"); if (!apiKey) { throw new Error("API_KEY not set"); } // Set environment variable env.set("DEBUG", "true"); env.set("LOG_LEVEL", "verbose"); // Delete environment variable env.delete("TEMP_VAR"); // Get all environment variables const allEnv = env.toObject(); console.log(allEnv); // With default value const port = env.get('PORT') || '3000'; // Load from .env file (exports to environment by default) await env.loadFromFile(".env"); // Load from multiple files (later files override earlier ones) const config = await env.loadFromFile([".env", ".env.local", ".env.production"]); // Load without exporting to process environment const config = await env.loadFromFile(".env", { export: false }); // Synchronous loading const configSync = env.loadFromFileSync(".env"); // Load from URL const config = await env.loadFromFile(new URL("file:///path/to/.env")); ``` -------------------------------- ### Inner Join Examples Source: https://github.com/jtmenchaca/tidy-ts/blob/main/docs/api/dataframe/joins.md Demonstrates different ways to perform an inner join using column names or key mappings. ```typescript df.innerJoin(other, "id") ``` ```typescript df.innerJoin(other, ["region", "product"]) ``` ```typescript df.innerJoin(other, { keys: { left: "user_id", right: "id" } }) ``` -------------------------------- ### rightJoin Examples Source: https://github.com/jtmenchaca/tidy-ts/blob/main/docs/api/dataframe/joins.md Demonstrates different ways to perform a right join. Use the simple API when column names match, or the advanced API for explicit control over keys and suffixes. ```typescript df.rightJoin(other, "id") ``` ```typescript df.rightJoin(other, ["region", "year"]) ``` ```typescript df.rightJoin(other, { keys: { left: "user_id", right: "id" } }) ``` -------------------------------- ### Install Monorepo Dependencies Source: https://github.com/jtmenchaca/tidy-ts/blob/main/repo-setup.md Installs all project dependencies using pnpm, creating symlinks for workspace packages and resolving wildcard dependencies. ```bash pnpm install ``` -------------------------------- ### Install Tidy-TS with Package Managers Source: https://github.com/jtmenchaca/tidy-ts/blob/main/README.md Install the @tidy-ts/dataframe package using your preferred package manager for Deno, Bun, pnpm, npm, or yarn. ```bash deno add jsr:@tidy-ts/dataframe // Deno bunx jsr add @tidy-ts/dataframe // bun pnpm add jsr:@tidy-ts/dataframe // pnpm npx jsr add @tidy-ts/dataframe // npm yarn add jsr:@tidy-ts/dataframe // yarn ``` -------------------------------- ### Root Deno Configuration Example Source: https://github.com/jtmenchaca/tidy-ts/blob/main/repo-setup.md Defines Deno workspace settings, compiler options, and exclusion rules for formatting and linting across the monorepo. ```jsonc { "version": "0.0.1", "compilerOptions": { "lib": ["deno.ns", "dom"], "jsx": "react-jsx", "jsxImportSource": "react" }, "fmt": { "exclude": [ "node_modules/", "**/*.md", "dist/**" ] }, "lint": { "exclude": [ "node_modules/**", "dist/**" ] }, "exclude": [ "**/node_modules/**", "dist/**", "node_modules/**" ], "workspace": [ "packages/*" ] } ``` -------------------------------- ### WASM-Powered Join Example Source: https://github.com/jtmenchaca/tidy-ts/blob/main/docs/api/dataframe/setup.md Shows an example of a WASM-powered join, highlighting that performance-critical operations like joins run in WebAssembly for significant speedups. ```typescript // WASM-POWERED OPERATIONS // Performance-critical operations run in WebAssembly (Rust) // - Joins: innerJoin, leftJoin, rightJoin, outerJoin // - Sorting: arrange() with complex multi-column sorts // - Statistics: mean, stdev, variance, correlation, t-tests // - Regression: GLM, linear models // - Distributions: normal, t, chi-square, etc. // Example: WASM-powered join (4-8x faster than pure JS) const orders = createDataFrame([...]); const customers = createDataFrame([...]); const result = orders.leftJoin(customers, "customer_id"); ``` -------------------------------- ### setupTidyTS Source: https://github.com/jtmenchaca/tidy-ts/blob/main/docs/api/dataframe/setup.md Initializes the WebAssembly module for tidy-ts statistical computations in browser environments. This function should be called once before using any WASM-backed statistical functions. In Node.js, Deno, or Bun, this function is a no-op. ```APIDOC ## setupTidyTS ### Description Setup function for browsers - preload and compile the WebAssembly module that powers statistical computations. Call this once before using any tidy-ts statistical or WASM-backed functions in browsers. In Node.js/Deno/Bun environments, this is a no-op as they load WASM synchronously on demand. ### Signature ```typescript setupTidyTS(url?: string | URL): Promise ``` ### Import ```typescript import { setupTidyTS, createDataFrame, stats as s } from "@tidy-ts/dataframe"; ``` ### Parameters - **url** (string | URL) - Optional URL or path to the tidy_ts_dataframe.wasm file. If omitted, automatically resolves the URL relative to the package location. Useful for custom CDN paths or local hosting scenarios. ### Returns Promise - Resolves when the WASM module is compiled and ready ### Examples ```typescript // BROWSER SETUP - Call once before using stats functions import { setupTidyTS, createDataFrame, stats as s } from "@tidy-ts/dataframe"; // Initialize WASM (required in browsers, no-op elsewhere) await setupTidyTS(); // Now you can use all tidy-ts features const df = createDataFrame([{ x: 1 }, { x: 2 }, { x: 3 }]); const meanValue = s.mean(df.x); // Custom WASM URL (CDN or local hosting) await setupTidyTS("https://cdn.example.com/tidy_ts_dataframe.wasm"); // Local path await setupTidyTS("/static/wasm/tidy_ts_dataframe.wasm"); ``` ### Best Practices - ✓ GOOD: Call setupTidyTS() once at app initialization before using stats functions - ✓ GOOD: The function is idempotent - calling it multiple times is safe (subsequent calls are no-ops) - ✓ GOOD: Use try/catch for graceful error handling if WASM fails to load - ✓ GOOD: In Node.js/Deno/Bun, setupTidyTS() is a no-op - safe to include unconditionally - ✓ GOOD: For custom deployments, pass the WASM URL as a parameter ### Anti-patterns - ❌ BAD: Using s.mean(), s.stdev(), or other WASM-backed stats functions before calling setupTidyTS() in browsers - will throw an error - ❌ BAD: Calling setupTidyTS() in a loop or on every component render - call once at app initialization ### Related `createDataFrame`, `s.mean`, `s.stdev` ```