Converts array to the type specified by to. This is a low-level interface;
most users should use as.data.frame() or as.vector() unless finer-grained
control is needed over the conversion. This function is an S3 generic
dispatching on to: developers may implement their own S3 methods for
custom vector types.
Arguments
- array
- to
A target prototype object describing the type to which
arrayshould be converted, orNULLto use the default conversion as returned byinfer_nanoarrow_ptype(). Alternatively, a function can be passed to perform an alternative calculation of the default ptype as a function ofarrayand the default inference of the prototype.- ...
Passed to S3 methods
Details
Conversions are implemented for the following R vector types:
logical(): Any numeric type can be converted tological()in addition to the bool type. For numeric types, any non-zero value is consideredTRUE.integer(): Any numeric type can be converted tointeger(); however, a warning will be signaled if the any value is outside the range of the 32-bit integer.double(): Any numeric type can be converted todouble(). This conversion currently does not warn for values that may not roundtrip through a floating-point double (e.g., very large uint64 and int64 values).character(): String and large string types can be converted tocharacter(). The conversion does not check for valid UTF-8: if you need finer-grained control over encodings, useto = blob::blob().Date: Only the date32 type can be converted to an R Date vector.
hms::hms(): Time32 and time64 types can be converted tohms::hms().difftime(): Time32, time64, and duration types can be converted to Rdifftime()vectors. The value is converted to match theunits()attribute ofto.blob::blob(): String, large string, binary, and large binary types can be converted toblob::blob().vctrs::list_of(): List, large list, and fixed-size list types can be converted tovctrs::list_of().data.frame(): Struct types can be converted todata.frame().vctrs::unspecified(): Any type can be converted tovctrs::unspecified(); however, a warning will be raised if any non-null values are encountered.
In addition to the above conversions, a null array may be converted to any
target prototype except data.frame(). Extension arrays are currently
converted as their storage type; dictionary-encoded arrays are not
currently supported.
Examples
array <- as_nanoarrow_array(data.frame(x = 1:5))
str(convert_array(array))
#> 'data.frame': 5 obs. of 1 variable:
#> $ x: int 1 2 3 4 5
str(convert_array(array, to = data.frame(x = double())))
#> 'data.frame': 5 obs. of 1 variable:
#> $ x: num 1 2 3 4 5