Skip to content

Append two Series

Source code

Description

Append two Series

Usage

<Series>$append(other, immutable = TRUE)

Arguments

other Series to append.
immutable Should the other Series be immutable? Default is TRUE.

Details

If immutable = FALSE, the Series object will not behave as immutable. This means that appending to this Series will affect any variable pointing to this memory location. This will break normal scoping rules of R. Setting immutable = FALSE is discouraged as it can have undesirable side effects and cloning Polars Series is a cheap operation.

Value

Series

Examples

library("polars")


# default immutable behavior, s_imut and s_imut_copy stay the same
s_imut = as_polars_series(1:3)
s_imut_copy = s_imut
s_new = s_imut$append(as_polars_series(1:3))
s_new
#> polars Series: shape: (6,)
#> Series: '' [i32]
#> [
#>  1
#>  2
#>  3
#>  1
#>  2
#>  3
#> ]
# the original Series didn't change
s_imut
#> polars Series: shape: (3,)
#> Series: '' [i32]
#> [
#>  1
#>  2
#>  3
#> ]
s_imut_copy
#> polars Series: shape: (3,)
#> Series: '' [i32]
#> [
#>  1
#>  2
#>  3
#> ]
# enabling mutable behavior requires setting a global option
withr::with_options(
  list(polars.strictly_immutable = FALSE),
  {
    s_mut = as_polars_series(1:3)
    s_mut_copy = s_mut
    s_new = s_mut$append(as_polars_series(1:3), immutable = FALSE)
    print(s_new)

    # the original Series also changed since it's mutable
    print(s_mut)
    print(s_mut_copy)
  }
)
#> polars Series: shape: (6,)
#> Series: '' [i32]
#> [
#>  1
#>  2
#>  3
#>  1
#>  2
#>  3
#> ]
#> polars Series: shape: (6,)
#> Series: '' [i32]
#> [
#>  1
#>  2
#>  3
#>  1
#>  2
#>  3
#> ]
#> polars Series: shape: (6,)
#> Series: '' [i32]
#> [
#>  1
#>  2
#>  3
#>  1
#>  2
#>  3
#> ]