Replace matching regex/literal substring in the name with a new value
Description
This will undo any previous renaming operations on the expression.
Due to implementation constraints, this method can only be called as the last expression in a chain. Only one name operation per expression will work.
Usage
<Expr>$name$replace(pattern, value, ..., literal = FALSE)
Arguments
pattern
|
A valid regular expression pattern, compatible with the
regex crate
\\_.
|
value
|
String that will replace the matched substring. |
…
|
These dots are for future extensions and must be empty. |
literal
|
Treat pattern as a literal string, not a regex.
|
Value
A polars expression
Examples
library("polars")
df <- pl$DataFrame(n_foo = 1, n_bar = 2)
df$select(pl$all()$name$replace("^n_", "col_"))
#> shape: (1, 2)
#> ┌─────────┬─────────┐
#> │ col_foo ┆ col_bar │
#> │ --- ┆ --- │
#> │ f64 ┆ f64 │
#> ╞═════════╪═════════╡
#> │ 1.0 ┆ 2.0 │
#> └─────────┴─────────┘
#> $`n_f@@`
#> Float64
#>
#> $`n_b@r`
#> Float64