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 a1d209f
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions R/as_polars_expr.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#' 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.list = function(x, ..., as_lit = TRUE) {
if (as_lit) {
pl$lit(x)
} else {
pl$lit(unlist(x))
}
}

0 comments on commit a1d209f

Please sign in to comment.