BiocFile-class | R Documentation |
BiocFile
is the base virtual class for high-level file
abstractions where subclasses are associated with a particular file format
or type. It wraps a low-level representation of a file, currently either a
path, URL, or connection object. We can represent a list of BiocFile
objects with a BiocFileList
.
BiocFileList(files)
resource(x)
resource(x) <- value
## S4 method for signature 'BiocFile'
resource(x)
## S4 replacement method for signature 'BiocFile,character_OR_connection'
resource(x) <- value
fileFormat(x)
## S4 method for signature 'character'
fileFormat(x)
## S4 method for signature 'BiocFile'
fileFormat(x)
## S4 method for signature 'BiocFile'
path(object, ...)
## S4 method for signature 'BiocFile'
show(object)
FileForFormat(path, format = file_ext(path), prefix = NULL, suffix = "File")
## S4 method for signature 'BiocFile'
as.character(x)
files |
|
x |
A |
object |
A |
... |
additional arguments to lower-level functions, not used. |
path , value |
Either a |
format |
|
prefix |
|
suffix |
|
For constructors, an instance of that class. For extractors such as
resource
and path
, typically a character
vector of the file path.
For FileForFormat
, a convenient instance of the class for which the
input file corresponds to.
In the code snippets below, x
represents a BiocFile
object.
path(x)
: Gets the path, as a character
vector, to the resource
represented by the BiocFile
object, if possible.
resource(x)
: Gets the low-level resource, either a character vector
(a path or URL) or a connection.
fileFormat(x)
: Gets a string identifying the file format. Can also
be called directly on a character file path, in which case it uses a
heuristic based on the file extension.
The prefix
and suffix
arguments are used to filter the class names to
those that match the pattern paste0(prefix, format, suffix)
. If either
prefix
or suffix
are NULL
, they are ignored. Note that the search is
case insensitive and does require the format
to be in the name of the
class.
Michael Lawrence
Implementing classes include: BigWigFile, TwoBitFile, BEDFile, GFFFile, WIGFile
## For our examples, we create a class called CSVFILE that extends BiocFile
.CSVFile <- setClass("CSVFile", contains = "BiocFile")
## Constructor
CSVFile <- function(resource) {
.CSVFile(resource = resource)
}
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), ...)
}
)
## Recommend CSVFile class for .csv files
temp <- tempfile(fileext = ".csv")
FileForFormat(temp)
## Create CSVFile
csv <- CSVFile(temp)
## Display path of file
path(csv)
## Display resource of file
resource(csv)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.