Skip to contents

These methods return an narrow_array() for R objects that don't involve copying or unnecessary allocating. Two excpetions are (1) ALTREP objects, which will be expanded, and (2) character vectors, which will be converted to UTF-8 and serialized as a single raw() vector.

Usage

# S3 method for `NULL`
as_narrow_array(x, ..., name = "")

# S3 method for logical
as_narrow_array(x, ..., name = "")

# S3 method for integer
as_narrow_array(x, ..., name = "")

# S3 method for double
as_narrow_array(x, ..., name = "")

# S3 method for character
as_narrow_array(x, ..., name = "")

# S3 method for factor
as_narrow_array(x, ..., name = "")

# S3 method for raw
as_narrow_array(x, ..., name = "")

# S3 method for data.frame
as_narrow_array(x, ..., name = "", nullable = FALSE)

Arguments

x

An object to convert to an narrow_array()

...

Passed to S3 methods

name

An optional name

nullable

TRUE if the type is semantically nullable

Value

An narrow_array()

Examples

as_narrow_array(NULL)
#> <narrow_array n[0]>
#> - schema:
#>   <narrow_schema 'n' at 0x55e69212e0f0>
#>   - format: n
#>   - name: 
#>   - flags: nullable
#>   - metadata:  list()
#>   - dictionary: NULL
#>   - children[0]:
#> - array_data:
#>   <narrow_array_data at 0x55e68fdd01d0>
#>   - length: 0
#>   - null_count: 0
#>   - offset: 0
#>   - buffers[0]:
#>   - dictionary: NULL
#>   - children[0]:
as_narrow_array(c(TRUE, FALSE, NA))
#> <narrow_array i[3]>
#> - schema:
#>   <narrow_schema 'i' at 0x55e6921a9d80>
#>   - format: i
#>   - name: 
#>   - flags: nullable
#>   - metadata:  list()
#>   - dictionary: NULL
#>   - children[0]:
#> - array_data:
#>   <narrow_array_data at 0x55e68fdd0280>
#>   - length: 3
#>   - null_count: 1
#>   - offset: 0
#>   - buffers[2]: List of 2
#>     $ : 'narrow_bitmask' raw 01
#>     $ : logi [1:3] TRUE FALSE NA
#>   - dictionary: NULL
#>   - children[0]:
as_narrow_array(1:10)
#> <narrow_array i[10]>
#> - schema:
#>   <narrow_schema 'i' at 0x55e691df8a10>
#>   - format: i
#>   - name: 
#>   - flags: nullable
#>   - metadata:  list()
#>   - dictionary: NULL
#>   - children[0]:
#> - array_data:
#>   <narrow_array_data at 0x55e69016aef0>
#>   - length: 10
#>   - null_count: 0
#>   - offset: 0
#>   - buffers[2]: List of 2
#>     $ : NULL
#>     $ : int [1:10] 1 2 3 4 5 6 7 8 9 10
#>   - dictionary: NULL
#>   - children[0]:
as_narrow_array(c(1.1, 2.2))
#> <narrow_array g[2]>
#> - schema:
#>   <narrow_schema 'g' at 0x55e691ba65d0>
#>   - format: g
#>   - name: 
#>   - flags: nullable
#>   - metadata:  list()
#>   - dictionary: NULL
#>   - children[0]:
#> - array_data:
#>   <narrow_array_data at 0x55e691f3d8f0>
#>   - length: 2
#>   - null_count: 0
#>   - offset: 0
#>   - buffers[2]: List of 2
#>     $ : NULL
#>     $ : num [1:2] 1.1 2.2
#>   - dictionary: NULL
#>   - children[0]:
as_narrow_array(as.raw(0x00))
#> <narrow_array C[1]>
#> - schema:
#>   <narrow_schema 'C' at 0x55e6919ee140>
#>   - format: C
#>   - name: 
#>   - flags: nullable
#>   - metadata:  list()
#>   - dictionary: NULL
#>   - children[0]:
#> - array_data:
#>   <narrow_array_data at 0x55e691e95e20>
#>   - length: 1
#>   - null_count: 0
#>   - offset: 0
#>   - buffers[2]: List of 2
#>     $ : NULL
#>     $ : raw 00
#>   - dictionary: NULL
#>   - children[0]:
as_narrow_array("fish")
#> <narrow_array u[1]>
#> - schema:
#>   <narrow_schema 'u' at 0x55e692153f40>
#>   - format: u
#>   - name: 
#>   - flags: nullable
#>   - metadata:  list()
#>   - dictionary: NULL
#>   - children[0]:
#> - array_data:
#>   <narrow_array_data at 0x55e68fdd01d0>
#>   - length: 1
#>   - null_count: 0
#>   - offset: 0
#>   - buffers[3]: List of 3
#>     $ : NULL
#>     $ : int [1:2] 0 4
#>     $ : raw [1:4] 66 69 73 68
#>   - dictionary: NULL
#>   - children[0]:
as_narrow_array(data.frame(x = 1:10, y = as.raw(1:10)))
#> <narrow_array +s[10]>
#> - schema:
#>   <narrow_schema '+s' at 0x55e6921a9d80>
#>   - format: +s
#>   - name: 
#>   - flags: 
#>   - metadata:  list()
#>   - dictionary: NULL
#>   - children[2]:
#>     <narrow_schema 'i' at 0x55e6922d7000>
#>     - format: i
#>     - name: x
#>     - flags: nullable
#>     - metadata:  list()
#>     - dictionary: NULL
#>     - children[0]:
#>     <narrow_schema 'C' at 0x55e69212e0f0>
#>     - format: C
#>     - name: y
#>     - flags: nullable
#>     - metadata:  list()
#>     - dictionary: NULL
#>     - children[0]:
#> - array_data:
#>   <narrow_array_data at 0x55e691f3d8f0>
#>   - length: 10
#>   - null_count: 0
#>   - offset: 0
#>   - buffers[1]: List of 1
#>     $ : NULL
#>   - dictionary: NULL
#>   - children[2]:
#>     <narrow_array_data at 0x55e68fdd0280>
#>     - length: 10
#>     - null_count: 0
#>     - offset: 0
#>     - buffers[2]: List of 2
#>       $ : NULL
#>       $ : int [1:10] 1 2 3 4 5 6 7 8 9 10
#>     - dictionary: NULL
#>     - children[0]:
#>     <narrow_array_data at 0x55e69016aef0>
#>     - length: 10
#>     - null_count: 0
#>     - offset: 0
#>     - buffers[2]: List of 2
#>       $ : NULL
#>       $ : raw [1:10] 01 02 03 04 ...
#>     - dictionary: NULL
#>     - children[0]: