This function will write out objects that have been assigned a format
with either format_stream() or the format argument to new_stream().
See examples.
Usage
write_stream(x, ...)
# S3 method for default
write_stream(x, data, ...)
# S3 method for stream_format_fst
write_stream(x, data, dir = NULL, ...)
# S3 method for stream_format_feather
write_stream(x, data, dir = NULL, ...)
# S3 method for stream_format_qs
write_stream(x, data, dir = NULL, ...)
# S3 method for stream_format_rds
write_stream(x, data, dir = NULL, ...)Arguments
- x
A
file_streamobject.- ...
Not used.
- data
An object to write.
- dir
An optional directory location to be used if not already in the
filespot inx.
Details
The default method always returns FALSE; other methods which get invoked
if a format was set will return TRUE. So, the user can always call
write_stream() and check the return value: if TRUE, the file was written
to disk and the data to not need to be returned; a FALSE return value
indicates that no format was set and the data should be returned.
Note the write methods can be invoked directly for a specific format
if no format was set (see examples).
Examples
ds <- temp_ds("example")
fs <- new_stream(2, locker = ds, format = "fst")
data <- data.frame(x = rnorm(10))
x <- lapply(fs, write_stream, data = data)
#> fstcore package v0.9.8
#> (OpenMP was not detected, using single threaded mode)
list.files(ds)
#> [1] "1-2.fst" "2-2.fst"
reset_locker(ds)
fs <- format_stream(fs, "rds")
x <- lapply(fs, write_stream, data = data)
list.files(ds)
#> [1] "1-2.rds" "2-2.rds"