io {BiocIO} | R Documentation |
The functions import
and export
load and save
objects from and to particular file formats. The rtracklayer package
implements support for a number of annotation and sequence formats.
export(object, con, format, ...) import(con, format, text, ...)
object |
The object to export. |
con |
The connection from which data is loaded or to which data
is saved. If this is a character vector, it is assumed to be a
filename and a corresponding file connection is created and then
closed after exporting the object. If a |
format |
The format of the output. If missing and |
text |
If |
... |
Parameters to pass to the format-specific method. |
If con
is missing, a character vector containing the string
output. Otherwise, nothing is returned.
Michael Lawrence
Format-specific options for the popular formats: GFF, BED, Bed15, bedGraph, WIG, BigWig
## To illustrate export(), import(), and yeild(), we create a class, CSVFILE .CSVFile <- setClass("CSVFile", contains = "BiocFile") ## Constructor CSVFile <- function(resource) { .CSVFile(resource = resource) } ## Define import setMethod("import", "CSVFile", function(con, format, text, ...) { read.csv(resource(con), ...) }) ## Define export setMethod("export", c("data.frame", "CSVFile"), function(object, con, format, ...) { write.csv(object, resource(con), ...) }) ## Usage temp <- tempfile(fileext = ".csv") csv <- CSVFile(temp) export(mtcars, csv) df <- import(csv)