Learn R Programming

arrow (version 8.0.0)

Scalar: Arrow scalars

Description

A Scalar holds a single value of an Arrow type.

Arguments

Factory

The Scalar$create() factory method instantiates a Scalar and takes the following arguments:

  • x: an R vector, list, or data.frame

  • type: an optional data type for x. If omitted, the type will be inferred from the data.

Usage

a <- Scalar$create(x)
length(a)

print(a) a == a

Methods

  • $ToString(): convert to a string

  • $as_vector(): convert to an R vector

  • $as_array(): convert to an Arrow Array

  • $Equals(other): is this Scalar equal to other

  • $ApproxEquals(other): is this Scalar approximately equal to other

  • $is_valid: is this Scalar valid

  • $null_count: number of invalid values - 1 or 0

  • $type: Scalar type

  • $cast(target_type, safe = TRUE, options = cast_options(safe)): cast value to a different type

Examples

Run this code
# NOT RUN {
Scalar$create(pi)
Scalar$create(404)
# If you pass a vector into Scalar$create, you get a list containing your items
Scalar$create(c(1, 2, 3))

# Comparisons
my_scalar <- Scalar$create(99)
my_scalar$ApproxEquals(Scalar$create(99.00001)) # FALSE
my_scalar$ApproxEquals(Scalar$create(99.000009)) # TRUE
my_scalar$Equals(Scalar$create(99.000009)) # FALSE
my_scalar$Equals(Scalar$create(99L)) # FALSE (types don't match)

my_scalar$ToString()
# }

Run the code above in your browser using DataLab