fileformats: Set or return list of registered file formats that we can...

View source: R/neuron-io.R

fileformatsR Documentation

Set or return list of registered file formats that we can read


fileformats returns format names, a format definition list or a table of information about the formats that match the given filter conditions.

registerformat registers a format in the io registry

getformatreader gets the function to read a file

getformatwriter gets the function to write a file


  format = NULL,
  ext = NULL,
  read = NULL,
  write = NULL,
  class = NULL,
  rval = c("names", "info", "all")

  format = NULL,
  ext = format,
  read = NULL,
  write = NULL,
  magic = NULL,
  magiclen = NA_integer_,
  class = NULL

getformatreader(file, class = NULL)

getformatwriter(format = NULL, file = NULL, ext = NULL, class = NULL)



Character vector naming the format


Character vector of file extensions (including periods)

read, write

Functions to read and write this format


The S3 class for the format (character vector e.g. 'neuron')


Character vector choosing what kind of return value fileformats will give.


Function to test whether a file is of this format


Optional integer specifying maximum number of bytes required from file header to determine file's type.


Path to a file


if a format argument is passed to fileformats it will be matched with partial string matching and if a unique match exists that will be returned.

getformatreader starts by reading a set number of bytes from the start off the current file and then checks using file extension and magic functions to see if it can identify the file. Presently formats are in a queue in alphabetical order, dispatching on the first match.


  • fileformats returns a character vector, matrix or list according to the value of rval.

  • getformatreader returns a list. The reader can be accessed with $read and the format can be accessed by $format.

  • getformatwriter returns a list. The writer can be accessed with $write.

getformatwriter output file

If getformatwriter is passed a file argument, it will be processed based on the registered fileformats information and the ext argument to give a final output path in the $file element of the returned list.

If ext='.someext' getformatwriter will use the specified extension to overwrite the default value returned by fileformats.

If ext=NULL, the default, and file='somefilename.someext' then file will be untouched and ext will be set to 'someext' (overriding the value returned by fileformats).

If file='somefile_without_extension' then the suppplied or calculated extension will be appended to file.

If ext=NA then the input file name will not be touched (even if it has no extension at all).

Note that if ext=NULL or ext=NA, then only the specified format or, failing that, the file extension will be used to query the fileformats database for a match.

See write.neuron for code to make this discussion more concrete.

See Also



# information about the currently registered file formats
## Not run: 

## End(Not run)
swc=tempfile(fileext = '.swc')
write.neuron(Cell07PNs[[1]], swc)

nat documentation built on Aug. 25, 2023, 5:16 p.m.