Arithmetic operators for RPolars objects

Description

Arithmetic operators for RPolars objects

Usage

``````## S3 method for class 'RPolarsExpr'
x + y

# S3 method for class 'RPolarsExpr'
x - y

# S3 method for class 'RPolarsExpr'
x * y

# S3 method for class 'RPolarsExpr'
x / y

# S3 method for class 'RPolarsExpr'
x ^ y

# S3 method for class 'RPolarsExpr'
x %% y

# S3 method for class 'RPolarsExpr'
x %/% y

# S3 method for class 'RPolarsSeries'
x + y

# S3 method for class 'RPolarsSeries'
x - y

# S3 method for class 'RPolarsSeries'
x * y

# S3 method for class 'RPolarsSeries'
x / y

# S3 method for class 'RPolarsSeries'
x ^ y

# S3 method for class 'RPolarsSeries'
x %% y

# S3 method for class 'RPolarsSeries'
x %/% y
``````

Arguments

 `x`, `y` numeric type of RPolars objects or objects that can be coerced such. Only `+` can take strings.

Value

A Polars object the same type as the input.

• `\\$add()`
• `\\$sub()`
• `\\$mul()`
• `\\$div()`
• `\\$pow()`
• `\\$mod()`
• `\\$floor_div()`
• `\\$add()`
• `\\$sub()`
• `\\$mul()`
• `\\$div()`
• `\\$pow()`
• `\\$mod()`
• `\\$floor_div()`

Examples

``````library(polars)

pl\$lit(5) + 10
``````
``````#> polars Expr: [(dyn float: 5.0) + (dyn float: 10.0)]
``````
``````5 + pl\$lit(10)
``````
``````#> polars Expr: [(dyn float: 5.0) + (dyn float: 10.0)]
``````
``````pl\$lit(5) + pl\$lit(10)
``````
``````#> polars Expr: [(dyn float: 5.0) + (dyn float: 10.0)]
``````
``````+pl\$lit(1)
``````
``````#> polars Expr: dyn float: 1.0
``````
``````# This will not raise an error as it is not actually evaluated.
expr = pl\$lit(5) + "10"
expr
``````
``````#> polars Expr: [(dyn float: 5.0) + (String(10))]
``````
``````# Will raise an error as it is evaluated.
tryCatch(
expr\$to_series(),
error = function(e) e
)
``````
``````#> <RPolarsErr_error: Execution halted with the following contexts
#>    0: In R: in \$select()
#>    0: During function call [.main()]
#>    1: Encountered the following error in Rust-Polars:
#>          invalid operation: arithmetic on string and numeric not allowed, try an explicit cast first: 'select' failed
#> >
``````
``````as_polars_series(5) + 10
``````
``````#> polars Series: shape: (1,)
#> Series: '' [f64]
#> [
#>  15.0
#> ]
``````
``````+as_polars_series(5)
``````
``````#> polars Series: shape: (1,)
#> Series: '' [f64]
#> [
#>  5.0
#> ]
``````
``````-as_polars_series(5)
``````
``````#> polars Series: shape: (1,)
#> Series: '' [f64]
#> [
#>  -5.0
#> ]
``````