Skip to content

Register all polars DataFrames/LazyFrames found in the environment

Source code

Description

Automatically maps variable names to table names.

Usage

<SQLContext>$register_globals(..., envir = parent.frame())

Arguments

Ignored.
envir The environment to search for polars DataFrames/LazyFrames.

Details

If a table with the same name is already registered, it will be overwritten.

Value

Returns the SQLContext object invisibly.

See Also

  • \$register()
  • \$register_many()
  • \$unregister()

Examples

library("polars")


df1 = pl$DataFrame(a = 1:3, b = c("x", NA, "z"))
df2 = pl$LazyFrame(a = 2:4, c = c("t", "w", "v"))

# Register frames directly from variables found in the current environment.
ctx = pl$SQLContext()$register_globals()
ctx$tables()
#> [1] "df1" "df2"
ctx$execute(
  "SELECT a, b, c FROM df1 LEFT JOIN df2 USING (a) ORDER BY a DESC"
)$collect()
#> shape: (3, 3)
#> ┌─────┬──────┬──────┐
#> │ a   ┆ b    ┆ c    │
#> │ --- ┆ ---  ┆ ---  │
#> │ i32 ┆ str  ┆ str  │
#> ╞═════╪══════╪══════╡
#> │ 3   ┆ z    ┆ w    │
#> │ 2   ┆ null ┆ t    │
#> │ 1   ┆ x    ┆ null │
#> └─────┴──────┴──────┘