Skip to content

Append expressions

Source code

Description

This is done by adding the chunks of other to this output.

Usage

<Expr>$append(other, upcast = TRUE)

Arguments

other Expr or something coercible to an Expr.
upcast Cast both Expr to a common supertype if they have one.

Value

Expr

Examples

library("polars")

# append bottom to to row
df = pl$DataFrame(list(a = 1:3, b = c(NA_real_, 4, 5)))
df$select(pl$all()$head(1)$append(pl$all()$tail(1)))
#> shape: (2, 2)
#> ┌─────┬──────┐
#> │ a   ┆ b    │
#> │ --- ┆ ---  │
#> │ i32 ┆ f64  │
#> ╞═════╪══════╡
#> │ 1   ┆ null │
#> │ 3   ┆ 5.0  │
#> └─────┴──────┘
# implicit upcast, when default = TRUE
pl$DataFrame(list())$select(pl$lit(42)$append(42L))
#> shape: (2, 1)
#> ┌─────────┐
#> │ literal │
#> │ ---     │
#> │ f64     │
#> ╞═════════╡
#> │ 42.0    │
#> │ 42.0    │
#> └─────────┘
pl$DataFrame(list())$select(pl$lit(42)$append(FALSE))
#> shape: (2, 1)
#> ┌─────────┐
#> │ literal │
#> │ ---     │
#> │ f64     │
#> ╞═════════╡
#> │ 42.0    │
#> │ 0.0     │
#> └─────────┘
pl$DataFrame(list())$select(pl$lit("Bob")$append(FALSE))
#> shape: (2, 1)
#> ┌─────────┐
#> │ literal │
#> │ ---     │
#> │ str     │
#> ╞═════════╡
#> │ Bob     │
#> │ false   │
#> └─────────┘