Export data out of R and write to disk.

export(object, ...)

# S4 method for matrix
export(object, ext = getOption("acid.export.ext",
  default = c("csv", "csv.gz", "csv.bz2", "tsv", "tsv.gz", "tsv.bz2")),
  dir = getOption("acid.export.dir", default = "."), file = NULL,
  overwrite = getOption("acid.overwrite", default = TRUE))

# S4 method for data.frame
export(object, ext = getOption("acid.export.ext",
  default = c("csv", "csv.gz", "csv.bz2", "tsv", "tsv.gz", "tsv.bz2")),
  dir = getOption("acid.export.dir", default = "."), file = NULL,
  overwrite = getOption("acid.overwrite", default = TRUE))

# S4 method for DataFrame
export(object, ext = getOption("acid.export.ext",
  default = c("csv", "csv.gz", "csv.bz2", "tsv", "tsv.gz", "tsv.bz2")),
  dir = getOption("acid.export.dir", default = "."), file = NULL,
  overwrite = getOption("acid.overwrite", default = TRUE))

# S4 method for sparseMatrix
export(object,
  ext = getOption("acid.export.sparse.ext", default = c("mtx", "mtx.gz",
  "mtx.bz2")), dir = getOption("acid.export.dir", default = "."),
  file = NULL, overwrite = getOption("acid.overwrite", default = TRUE))

# S4 method for GRanges
export(object, ext = getOption("acid.export.ext",
  default = c("csv", "csv.gz", "csv.bz2", "tsv", "tsv.gz", "tsv.bz2")),
  dir = getOption("acid.export.dir", default = "."), file = NULL,
  overwrite = getOption("acid.overwrite", default = TRUE))

# S4 method for SummarizedExperiment
export(object, name = NULL,
  dir = getOption("acid.export.dir", default = "."),
  compress = getOption("acid.export.compress", default = FALSE))

# S4 method for SingleCellExperiment
export(object, name = NULL,
  dir = getOption("acid.export.dir", default = "."),
  compress = getOption("acid.export.compress", default = FALSE))

Arguments

object

Object. An object supporting dim(), or a supported class capable of being coerced to data.frame, to be written to disk.

ext

character(1). Output file format extension. Uses match.arg(), where applicable.

dir

character(1). Directory path.

file

character(1). File path. When left unset (default), the ext and dir arguments will be used instead.

overwrite

logical(1). Overwrite existing file on disk.

name

character(1). Name to use on disk. If NULL, will use the name of the object instead.

compress

logical(1). Apply gzip compression to all files.

...

Additional arguments.

Value

Invisible character. File path(s).

Note

Updated 2019-10-12.

Row names

Some export utilities in R have a tendency to drop row names when writing to disk in CSV format. For example, the readr family of functions never write row names by design. This is a really poor default setting for handling genomic data, which often contain gene identifiers in the row names. Here we're performing any internal tibble coercion step to ensure row names are always moved to a "rowname" column in the CSV export.

Exporting vectors

Use writeLines() instead of export() to write vectors to disk. An S4 character method may be defined in a future update, but it is intentionally unsupported in the current release.

Debugging

Note that this function currently wraps data.table::fwrite() by default for exporting data.frame and matrix class objects. If you encounter any stack imbalance or segfault warnings during export, these are errors from data.table.

See also

Examples

counts <- matrix(data = seq_len(100L), nrow = 10) export(counts, ext = "csv")
#> Exporting 'counts.csv' using 'data.table::fwrite()'.
## Clean up. file.remove("counts.csv")
#> [1] TRUE