Skip to contents

Export data from R

Usage

export(object, con, ...)

# S4 method for Cellosaurus,character
export(object, con, ...)

Arguments

object

Object.

con

character(1) or connection. Data connection. Use character(1) to represent a file path.

...

Passthrough arguments to DFrame method.

Value

Invisible character or list of file paths.

Note

Updated 2023-09-22.

Output file format extension

matrix supported arguments:

  • Comma separated values (CSV): "csv", "csv.bz2", "csv.gz", "csv.xz", "csv.zip".

  • Tab separated values (TSV): "tsv", "tsv.bz2", "tsv.gz", "tsv.xz", "tsv.zip".

Matrix (sparseMatrix) supported arguments:

  • MatrixMarket exchange (MTX): "mtx", "mtx.bz2", "mtx.gz", "mtx.xz", "mtx.zip".

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.

Debugging

Note that this function currently wraps readr::write_delim() by default for exporting DFrame, data.frame, and matrix class objects.

Examples

data(cello)

## Cellosaurus ====
object <- cello
tempdir <- AcidBase::tempdir2()
con <- file.path(tempdir, "cello.csv")
x <- export(object = object, con = con)
#> → Exporting /private/var/folders/l1/8y8sjzmn15v49jgrqglghcfr0000gn/T/RtmpKdUQTh/awSFO40miV-169661505729345/cello.csv using base::`write.table()`.
print(x)
#> [1] "/private/var/folders/l1/8y8sjzmn15v49jgrqglghcfr0000gn/T/RtmpKdUQTh/awSFO40miV-169661505729345/cello.csv"
AcidBase::unlink2(tempdir)