| IO {BiocIO} | R Documentation |
Import and export
Description
The functions import and export load and save objects from
and to particular file formats.
Usage
import(con, format, text, ...)
## S4 method for signature 'connection,character,ANY'
import(con, format, text, ...)
## S4 method for signature 'connection,missing,ANY'
import(con, format, text, ...)
## S4 method for signature 'character,missing,ANY'
import(con, format, text, ...)
## S4 method for signature 'character,character,ANY'
import(con, format, text, ...)
## S4 method for signature 'missing,ANY,character'
import(con, format, text, ...)
export(object, con, format, ...)
## S4 method for signature 'ANY,connection,character'
export(object, con, format, ...)
## S4 method for signature 'ANY,connection,missing'
export(object, con, format, ...)
## S4 method for signature 'ANY,missing,character'
export(object, con, format, ...)
## S4 method for signature 'ANY,character,missing'
export(object, con, format, ...)
## S4 method for signature 'ANY,character,character'
export(object, con, format, ...)
## S4 method for signature 'CompressedFile,missing,ANY'
import(con, format, text, ...)
## S4 method for signature 'ANY,CompressedFile,missing'
export(object, con, format, ...)
Arguments
con |
The connection from which data is loaded or to which data is
saved. If this is a |
format |
The format of the output. If missing and |
text |
If |
... |
Parameters to pass to the format-specific method. |
object |
The object to export. |
Value
If con is missing, a character vector containing the string output.
Otherwise, nothing is returned.
Author(s)
Michael Lawrence
See Also
Format-specific options for the popular formats: GFF, BED, Bed15, bedGraph, WIG, BigWig
Examples
## 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)