Skip to content

Commit

Permalink
WIP feat: new generic function as_polars_expr() [skip ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
eitsupi committed Mar 31, 2024
1 parent acc29eb commit bf2fe06
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions R/as_polars_expr.R
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit bf2fe06

Please sign in to comment.