phplyr

Contributing

Development

Tests

The tests use Pest and run under PHP 8.3, 8.4, and 8.5. They call functions through pipe(), so they parse on every version. tests/Pipe/ holds the tests written with |>; bin/test leaves them out before PHP 8.5.

composer install
bin/test                 # loads .ext/libphit.dylib when present
NO_EXT=1 bin/test        # pure-PHP descriptive statistics
PHP=/path/to/php83 bin/test

The method chain’s @method list in src/Chain.php is generated. After adding or changing a table function, run bin/chain-docblock; a test fails while the list is out of date.

Most tests compare phplyr with R. The scripts in tests/r/ run the same pipelines with dplyr and tidyr and write JSON fixtures to tests/Fixtures/:

Rscript tests/r/reference.R   # single-table functions, windows, across, tidyselect
Rscript tests/r/expr.R        # expressions
Rscript tests/r/joins.R       # joins and rowwise
Rscript tests/r/join_by.R     # join_by() conditions
Rscript tests/r/tidyr.R       # tidyr functions
Rscript tests/r/rows.R        # set operations, rows_*(), dplyr 1.2 helpers
Rscript tests/r/coverage.R    # functions added after phplyr 0.1.0
Rscript tests/r/models.R      # lm() and glm() coefficients
Rscript tests/r/janitor.R     # janitor functions (needs the janitor package)

composer lint checks the naming conventions with PHP_CodeSniffer.

Documentation

The site is a Quarto project in docs/. Code examples live in docs/examples/*.php. bin/docs-examples runs each one with docs/data as the working directory and writes docs/examples/_<name>.md with the code and its output, which the pages include. Rendering never executes PHP.

An example uses |>, and docs/examples/<name>.chain.php beside it is the same example as a method chain. bin/docs-examples runs both and fails if their output differs. The page shows the two in tabs labeled “PHP 8.5+” and “PHP 8.3–8.4”, with the output once. bin/docs-examples needs PHP 8.5, and it loads phit from .ext/libphit.dylib for the model examples.

PHP=/path/to/php85 bin/docs-examples   # refresh example output
PHP=/path/to/php85 bin/render-docs     # examples, quarto render, publish to docs/

Commit the rendered HTML. phpstats.org imports it from the commit it pins and serves it at https://phplyr.phpstats.org/docs. GitHub Pages serves redirects to those pages, which .github/workflows/pages.yml builds with bin/pages-redirects.

Site content

site/ holds phplyr’s content for phplyr.phpstats.org. The phpstats site reads it at a pinned commit.

Path Contents Made by
site/site.json Manifest: summary, install, example, docs pages, and file lists bin/site-manifest
site/benchmarks/backends.json Backend and dplyr timings bin/site-benchmarks, from docs/benchmarks/
site/verifications/*.json Every test that checks phplyr against R, with its assertion count and largest floating-point error bin/site-verifications
site/vignettes/*.php Interactive examples the site runs on each request By hand
site/data/ Data files for the vignettes By hand

bin/site-verifications runs the test suite with PHPLYR_VERIFY_LOG set. Each test that reads an R fixture through rReference() then logs its assertions and the differences recorded by expectClose(). The script writes nothing unless every test passes. Set POLARS_PHP to a PHP command that loads php_polars to add the PolarsTable parity file.

To refresh the benchmarks, run bench/backends.php --csv-dir=bench/data, then Rscript bench/backends.R, then bin/site-benchmarks. tests/SiteTest.php runs each vignette at its default inputs.

Layout

Path Contents
src/functions/verbs.php Single-table functions
src/functions/chain.php, src/Chain.php phplyr() method chains and pipe()
src/functions/vectors.php Summary, window, and conditional helpers
src/functions/select.php tidyselect helpers and across()
src/functions/joins.php, rows.php Joins, set operations, and rows_*()
src/functions/groups.php Group utilities, binding, and model adapters
src/functions/tidyr.php tidyr functions
src/Vec.php The per-group vector expression behind the helpers
src/Ops.php Group-vector primitives over the Table contract

From phpstats/phplyr@d319dc5.