export: Import and export

ioR Documentation

Import and export


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, ...)



The object to export.


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 BiocFile derivative, the data is loaded from or saved to the underlying resource. If missing, the function will return the output as a character vector, rather than writing to a connection.


The format of the output. If missing and con is a filename, the format is derived from the file extension. This argument is unnecessary when con is a derivative of BiocFile.


If con is missing, this can be a character vector directly providing the string data to import.


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

See Also

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 <-
      .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)

Bioconductor/BiocIO documentation built on May 15, 2022, 2:19 a.m.