Expand description
A tiny arithmetic expression evaluator for computed aesthetics — so
aes can map e.g. "pop / 1e6", "log(gdp)", or "a * b + 1" instead of a
bare column name. Anything that isn’t an existing column is parsed and
evaluated per row against the data’s numeric columns.
Grammar (standard precedence, ^ right-associative):
expr := term (('+'|'-') term)*, term := factor (('*'|'/'|'%') factor)*,
factor := unary ('^' factor)?, unary := ('-'|'+') unary | primary,
primary := number | ident | ident '(' expr ')' | '(' expr ')'.
Functions: ln/log, log10, log2, sqrt, exp, abs, sin, cos,
tan, floor, ceil, round, sign.
Functions§
- eval_
expression - Evaluate
exprover every row ofdata, producing oneValueper row (non-finite results becomeValue::Na). ReturnsNoneif the string is not a valid expression or references no existing column (so a plain unknown column name / typo is left for the caller to handle, not silently computed).