Skip to contents

Imports a documented table as comma-separated variable. A wrapper for as.csv.character that also reads associated yamlet metadata, if present, and applies it as attributes.

Usage

# S3 method for class 'character'
io_csv(
  x,
  ext = getOption("yamlet_extension", ".yaml"),
  meta = NULL,
  gz = NULL,
  ...
)

Arguments

x

character file path; passed to as.csv.character (by method dispatch)

ext

extension for metadata equivalent of x

meta

explicit file path for metadata; if null, ext is appended to x after removing (final) extension, if any

gz

logical; guessed by default from x; if TRUE, '.gz' extension enforced present for x and absent for default meta

...

passed to as.csv.character and to decorate

Value

data.frame

Examples

example(io_csv)
#> 
#> io_csv> # generate some decorated data
#> io_csv> file <- system.file(package = 'yamlet', 'extdata','quinidine.csv')
#> 
#> io_csv> x <- decorate(file)
#> 
#> io_csv> # get a temporary filepath
#> io_csv> out <- file.path(tempdir(), 'out.csv')
#> 
#> io_csv> # save file using io_csv (returns filepath)
#> io_csv> foo <- io_csv(x, out)
#> 
#> io_csv> stopifnot(identical(out, foo))
#> 
#> io_csv> # read using this filepath
#> io_csv> y <- io_csv(foo)
#> 
#> io_csv> # lossless round-trip (ignoring source attribute)
#> io_csv> attr(x, 'source') <- NULL
#> 
#> io_csv> attr(y, 'source') <- NULL
#> 
#> io_csv> stopifnot(identical(x, y))