Export data from R
Usage
export(object, con, ...)
# S4 method for SingleCellExperiment,character
export(object, con, compress = FALSE, overwrite = TRUE, quiet = FALSE)
Arguments
- object
Object.
- con
character(1)
orconnection
. Data connection. Usecharacter(1)
to represent a file path.- compress
logical(1)
orcharacter(1)
. These character strings are currently allowed forsave()
:"gzip"
,"bzip2"
, or"xz"
.- overwrite
logical(1)
. Overwrite existing file on disk.- quiet
logical(1)
. Perform command quietly, suppressing messages.- ...
Additional arguments.
Details
This method extends SummarizedExperiment
but also handles export of the
reducedDims
slot (i.e. containing UMAP, tSNE, and PCA).
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.
See also
Examples
data(SingleCellExperiment_splatter, package = "AcidTest")
## SingleCellExperiment ====
object <- SingleCellExperiment_splatter
con <- AcidBase::tempdir2()
x <- export(object = object, con = con)
#> → Exporting <SummarizedExperiment> to /private/var/folders/l1/8y8sjzmn15v49jgrqglghcfr0000gn/T/Rtmp7m7qFg/EUrhFDv6iY-171156693674602.
#> → Exporting assays "counts" to /private/var/folders/l1/8y8sjzmn15v49jgrqglghcfr0000gn/T/Rtmp7m7qFg/EUrhFDv6iY-171156693674602/assays.
#> → Exporting /private/var/folders/l1/8y8sjzmn15v49jgrqglghcfr0000gn/T/Rtmp7m7qFg/EUrhFDv6iY-171156693674602/assays/counts.mtx using Matrix::`writeMM()`.
#> → Exporting /private/var/folders/l1/8y8sjzmn15v49jgrqglghcfr0000gn/T/Rtmp7m7qFg/EUrhFDv6iY-171156693674602/assays/counts.mtx.rownames using base::`writeLines()`.
#> → Exporting /private/var/folders/l1/8y8sjzmn15v49jgrqglghcfr0000gn/T/Rtmp7m7qFg/EUrhFDv6iY-171156693674602/assays/counts.mtx.colnames using base::`writeLines()`.
#> ℹ Dropping 2 non-atomic columns: "geneSynonyms", "ncbiGeneId".
#> → Exporting /private/var/folders/l1/8y8sjzmn15v49jgrqglghcfr0000gn/T/Rtmp7m7qFg/EUrhFDv6iY-171156693674602/rowData.csv using base::`write.table()`.
#> → Exporting /private/var/folders/l1/8y8sjzmn15v49jgrqglghcfr0000gn/T/Rtmp7m7qFg/EUrhFDv6iY-171156693674602/colData.csv using base::`write.table()`.
print(x)
#> $assays
#> $assays$counts
#> matrix
#> "/private/var/folders/l1/8y8sjzmn15v49jgrqglghcfr0000gn/T/Rtmp7m7qFg/EUrhFDv6iY-171156693674602/assays/counts.mtx"
#> rownames
#> "/private/var/folders/l1/8y8sjzmn15v49jgrqglghcfr0000gn/T/Rtmp7m7qFg/EUrhFDv6iY-171156693674602/assays/counts.mtx.rownames"
#> colnames
#> "/private/var/folders/l1/8y8sjzmn15v49jgrqglghcfr0000gn/T/Rtmp7m7qFg/EUrhFDv6iY-171156693674602/assays/counts.mtx.colnames"
#>
#>
#> $rowData
#> [1] "/private/var/folders/l1/8y8sjzmn15v49jgrqglghcfr0000gn/T/Rtmp7m7qFg/EUrhFDv6iY-171156693674602/rowData.csv"
#>
#> $colData
#> [1] "/private/var/folders/l1/8y8sjzmn15v49jgrqglghcfr0000gn/T/Rtmp7m7qFg/EUrhFDv6iY-171156693674602/colData.csv"
#>
AcidBase::unlink2(con)