Read a single neuron from a file

read.neuron(f, format = NULL, class = c("neuron", "ngraph"), ...)



Path to file. This can be a URL, in which case the file is downloaded to a temporary location before reading.


The file format of the neuron. When format=NULL, the default, read.neuron will infer the file format from the extension or file header (aka magic) using the fileformats registry.


The class of the returned object - presently either "neuron" or "ngraph"


additional arguments passed to format-specific readers


This function will handle neuron and dotprops objects saved in R .rds or .rda format by default. Additional file formats can be registered using fileformats.

At the moment the following formats are supported using file readers already included with the nat package:

  • swc See read.neuron.swc. SWC files can also return an ngraph object containing the neuron structure in a (permissive) general graph format that also contains the 3D positions for each vertex.

  • neuroml See read.neuron.neuroml

  • fijitraces See read.neuron.fiji. The file format used by the Simple Neurite Tracer plugin of Fiji/ImageJ.

  • hxlineset,hxskel Two distinct fileformats used by Amira. hxlineset is the generic one, hxskel is used by the hxskeletonize extension of Schmitt and Evers (see refs).

  • rda,rds Native R cross-platform binary formats (see load, readRDS). Note that RDS only contains a single unnamed neuron, whereas rda contains one or more named neurons.

  • obj,ply 3D Mesh formats encoding surface models of neurons. These depend on the suggested package Rvcg (for 'ply' format) and readobj (for Wavefront 'obj' format).


Schmitt, S. and Evers, J. F. and Duch, C. and Scholz, M. and Obermayer, K. (2004). New methods for the computer-assisted 3-D reconstruction of neurons from confocal image stacks. Neuroimage 4, 1283--98. doi:10.1016/j.neuroimage.2004.06.047

See also


if (FALSE) { # note that we override the default NeuronName field n=read.neuron(system.file("tests/testthat/testdata","neuron","EBT7R.CNG.swc",package='nat'), NeuronName="EBT7R") # use a function to set the NeuronName field n3=read.neuron(system.file("tests/testthat/testdata","neuron","EBT7R.CNG.swc",package='nat'), NeuronName=function(x) sub("\\..*","",x)) # show the currently registered file formats that we can read fileformats(class='neuron', read=TRUE) }