Skip to content

Add a prefix to all fields name of a struct

Source code

Description

Add a prefix to all fields name of a struct

Usage

<Expr>$name$prefix_fields(prefix)

Arguments

prefix Prefix to add to the field name.

Value

Expr

Examples

library(polars)

df = pl$DataFrame(a = 1, b = 2)$select(
  pl$struct(pl$all())$alias("my_struct")
)

df$with_columns(pl$col("my_struct")$name$prefix_fields("col_"))$unnest()
#> shape: (1, 2)
#> ┌───────┬───────┐
#> │ col_a ┆ col_b │
#> │ ---   ┆ ---   │
#> │ f64   ┆ f64   │
#> ╞═══════╪═══════╡
#> │ 1.0   ┆ 2.0   │
#> └───────┴───────┘