From bf2fe06e463e0fb21bda7cb0e341dcc3636a1bfe Mon Sep 17 00:00:00 2001 From: eitsupi Date: Sun, 31 Mar 2024 04:10:04 +0000 Subject: [PATCH] WIP feat: new generic function `as_polars_expr()` [skip ci] --- R/as_polars_expr.R | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 R/as_polars_expr.R diff --git a/R/as_polars_expr.R b/R/as_polars_expr.R new file mode 100644 index 000000000..d54f11cc7 --- /dev/null +++ b/R/as_polars_expr.R @@ -0,0 +1,31 @@ +#' Similar to `parse_as_expression` in Python Polars. +as_polars_expr = function(x, ...) { + UseMethod("as_polars_expr") +} + + +as_polars_expr.default(x, ...) = function(x, ...) { + pl$lit(x) +} + + +as_polars_expr.RPolarsExpr = function(x, ...) { + x +} + + +as_polars_expr.character = function(x, ..., as_lit = FALSE) { + if (as_lit) { + pl$lit(x) + } else { + pl$col(x) + } +} + + +as_polars_expr.RPolarsThen = function(x, ...) { + x$otherwise(NULL) +} + + +as_polars_expr.RPolarsChainedThen = as_polars_expr.RPolarsThen