write_stream: Writer functions for stream_file objects

View source: R/stream-write.R

write_streamR Documentation

Writer functions for stream_file objects

Description

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, ...)

## Default S3 method:
write_stream(x, data, ...)

## S3 method for class 'stream_format_fst'
write_stream(x, data, dir = NULL, ...)

## S3 method for class 'stream_format_feather'
write_stream(x, data, dir = NULL, ...)

## S3 method for class 'stream_format_qs'
write_stream(x, data, dir = NULL, ...)

## S3 method for class 'stream_format_rds'
write_stream(x, data, dir = NULL, ...)

Arguments

x

A file_stream object.

...

Not used.

data

An object to write.

dir

An optional directory location to be used if not already in the file spot in x.

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).

Value

A logical value indicating if the output was written or not.

See Also

format_stream(), ext_stream(), locate_stream(), new_stream(), file_stream()

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)

list.files(ds)

reset_locker(ds)

fs <- format_stream(fs, "rds")

x <- lapply(fs, write_stream, data = data)

list.files(ds)


mrgsim.parallel documentation built on March 18, 2022, 7:52 p.m.