Define an inline sink format
sink_format.RdCreate a format definition inline without registering it globally. Useful for one-off formats or when you don't want to modify the global registry.
Examples
# Define a custom format inline
my_format <- sink_format(
writer = ~ jsonlite::write_json(.x, .path, pretty = TRUE),
reader = ~ jsonlite::read_json(.path),
ext = ".json"
)
# Use with sink_quick
sink_quick("data", write = my_format$writer, read = my_format$reader)
#> $fields
#> [1] "data"
#>
#> $dir
#> [1] "artifacts://_quick"
#>
#> $template
#> [1] "{.stage}/{.field}/{.row_key}"
#>
#> $format
#> [1] "custom"
#>
#> $writer
#> function (x, path, ...)
#> {
#> .write_atomic_generic(writer, x, path, ...)
#> }
#> <bytecode: 0x55bd752d5cd0>
#> <environment: 0x55bd68597fa0>
#>
#> $reader
#> function (path, ...)
#> {
#> .path <- path
#> eval(expr, envir = environment())
#> }
#> <bytecode: 0x55bd68823600>
#> <environment: 0x55bd68824be0>
#>
#> $overwrite
#> [1] "skip"
#>
#> $checksum
#> [1] TRUE
#>
#> $sidecar
#> [1] "json"
#>
#> $autoload
#> [1] FALSE
#>
#> $ext
#> [1] ""
#>
#> $build_path_fn
#> function (spec, row, stage_name, field)
#> {
#> base_dir <- if (is.function(dir)) {
#> resolve_path(dir(row = row, stage = stage_name, field = field))
#> }
#> else {
#> resolve_path(dir)
#> }
#> template_data <- row
#> template_data$.stage <- stage_name
#> template_data$.field <- field
#> template_data$.row_key <- .row_key(row)
#> rel_path <- as.character(glue::glue_data(template_data, template))
#> if (!grepl("\\.[A-Za-z0-9]+$", rel_path) && nzchar(ext)) {
#> rel_path <- paste0(rel_path, ext)
#> }
#> .sink_safe_join(base_dir, rel_path)
#> }
#> <bytecode: 0x55bd752d60f8>
#> <environment: 0x55bd68597fa0>
#>
#> $compress
#> NULL
#>
#> attr(,"class")
#> [1] "parade_sink"