Learn R Programming

mrgsim.parallel (version 0.3.0)

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

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

Value

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

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

See Also

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

Examples

Run this code
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)

Run the code above in your browser using DataLab