Guide
Compatibility and limitations
PHP versions
phplyr supports PHP 8.3, 8.4, and 8.5. CI tests all three on Linux.
The pipe operator |> is PHP 8.5 syntax. On PHP 8.3 and 8.4, the same pipelines are method chains, or calls to pipe(). Every function works on all three versions.
Requirements
phplyr requires the mbstring extension. Composer installs these with phplyr:
- phibble (
phpstats/phibble0.3, 0.4, or 0.5), which provides the tables. phibble requires PHP’s PDO extension. symfony/polyfill-php84, which provides PHP 8.4 functions on PHP 8.3.
Optional extensions
| Extension | Enables |
|---|---|
| phit | lm(), glm(), lmer(), and glmer(), and native mean(), sd(), var_(), median(), and quantile() |
| phpolars | phibble’s PolarsTable backend |
| intl | Transliteration in make_clean_names() and clean_names() that matches R’s janitor |
| A PDO driver (SQLite, PostgreSQL, or MySQL) | Database tables through Phibble\tbl() |
Without phit, the descriptive helpers run in PHP, and the model functions throw a RuntimeException that names the missing function. phit-polyfill defines the model functions in PHP. See Models. Without intl, make_clean_names() transliterates with iconv, and some names can differ from janitor’s.
Backends
A phplyr function calls the methods of phibble’s Table contract, so a pipeline runs on any table that implements it:
Phibble\DataFrameholds the data in PHP memory.Phibble\tbl($pdo, 'table')builds SQL for SQLite, PostgreSQL, or MySQL. A function given a PHP closure, and an expression without a SQL translation, runs the query so far, loads the rows, and continues in memory. Databases and expressions lists those expressions.Phibble\Polars\PolarsTablebelongs to phibble and runs pipelines in Polars through the phpolars extension. A closure step converts the data to aDataFrameand back.
The test suite runs about 120 pipelines on both DataFrame and PolarsTable and requires the same columns, types, groups, and rows from each.
Not supported
- Bare column names and tidy evaluation. Columns are strings, and expressions are closures, helpers, or
col()expressions. mutate(_keep: 'used')and_keep: 'unused'with closures. These work with expression arguments such ascol('x')->mul(2), whose columns phplyr can read. A PHP closure does not expose the columns it reads, so phplyr throws anInvalidArgumentException.cur_data()andcur_data_all(), which dplyr has deprecated. Usepick().- Data frame columns and
across(.unpack).pack()makes a column of named arrays. - The scoped
_at,_if, and_allvariants, such asmutate_at(). Useacross(). - janitor’s
adorn_*()functions and three-waytabyl().
Differences in behavior
_bysorts groups. dplyr keeps the order of first appearance for.by. phplyr sorts by key, as it does forgroup_by().- Strings are UTF-8. String functions count UTF-8 characters.
- Date-times parse to UTC unless a function is given
tz:, whatever PHP’s default time zone is, as in lubridate. - Models return arrays.
lm()and the other model functions return phit’s result array, with R’s coefficient names incolumns, in place of a model object.
From phpstats/phplyr@d319dc5.