Skip to content

Get a single column by name

Source code

Description

Get a single column by name

Usage

<DataFrame>$get_column(name)

Arguments

name Name of the column to retrieve.

Value

A polars Series

Examples

library("polars")

df <- pl$DataFrame(foo = 1:3, bar = 4:6)
df$get_column("foo")
#> shape: (3, 1)
#> ┌─────┐
#> │ foo │
#> │ --- │
#> │ i32 │
#> ╞═════╡
#> │ 1   │
#> │ 2   │
#> │ 3   │
#> └─────┘
tryCatch(
  df$get_column("baz"),
  error = function(e) print(e)
)
#> <error/rlang_error>
#> Error in `df$get_column()`:
#> ! Evaluation failed in `$get_column()`.
#> Caused by error:
#> ! Column(s) not found: "baz" not found
#> ---
#> Backtrace:
#>      ▆
#>   1. ├─base::tryCatch(df$get_column("baz"), error = function(e) print(e))
#>   2. │ └─base (local) tryCatchList(expr, classes, parentenv, handlers)
#>   3. │   └─base (local) tryCatchOne(expr, names, parentenv, handlers[[1L]])
#>   4. │     └─base (local) doTryCatch(return(expr), name, parentenv, handler)
#>   5. └─df$get_column("baz")
#>   6.   ├─polars:::wrap(self$`_df`$get_column(name)) at r-polars/R/dataframe-frame.R:297:3
#>   7.   │ └─rlang::try_fetch(...) at r-polars/R/utils-wrap.R:3:3
#>   8.   │   ├─base::tryCatch(...)
#>   9.   │   │ └─base (local) tryCatchList(expr, classes, parentenv, handlers)
#>  10.   │   │   └─base (local) tryCatchOne(expr, names, parentenv, handlers[[1L]])
#>  11.   │   │     └─base (local) doTryCatch(return(expr), name, parentenv, handler)
#>  12.   │   └─base::withCallingHandlers(...)
#>  13.   └─self$`_df`$get_column(name) at r-polars/R/utils-wrap.R:3:3
#>  14.     └─polars:::.savvy_wrap_PlRSeries(...) at r-polars/R/000-wrappers.R:434:5