If file is not specified the neuron's InputFileName field will be checked (for a dotprops object it will be the 'file' attribute). If this is missing there will be an error. If dir is specified it will be combined with basename(file). If file is specified but format is not, it will be inferred from file's extension.

write.neuron(
  n,
  file = NULL,
  dir = NULL,
  format = NULL,
  ext = NULL,
  Force = FALSE,
  MakeDir = TRUE,
  metadata = NULL,
  ...
)

Arguments

n

A neuron

file

Path to output file

dir

Path to directory (this will replace dirname(file) if specified)

format

Unique abbreviation of one of the registered file formats for neurons including 'swc', 'hxlineset', 'hxskel' (skeletons) and 'ply', 'obj' (neuron meshes). If no format can be extracted from the filename or the ext parameter, then it defaults to 'swc' for skeletons and 'ply' for meshes.

ext

Will replace the default extension for the filetype and should include the period e.g. ext='.amiramesh' or ext='_reg.swc'. The special value of ext=NA will prevent the extension from being changed or added e.g. if the desired file name does not have an extension.

Force

Whether to overwrite an existing file

MakeDir

Whether to create directory implied by file argument.

metadata

Whether to encode some metadata in the header file (currently only supported for SWC format). Either a data.frame or TRUE to indicate that the attached data.frame should be written. Default FALSE.

...

Additional arguments passed to selected writer function

Value

return value

Details

Note that if file does not have an extension then the default extension for the specified format will be appended. This behaviour can be suppressed by setting ext=NA.

If you find that some software rejects your SWC files, try setting normalise.ids=TRUE (see examples). This will ensure that the vertex ids are sequentially ascending integers (1:N). The default value of normalise.ids=NA will normalise PointNo vertex ids only when a vertex is connected (by the Parent field) to a vertex that had not yet been defined. Many readers make the assumption that this is true. When normalise.ids=FALSE the vertex ids will not be touched.

Examples

# show the currently registered file formats that we can write
fileformats(class='neuron', write=TRUE)
#> [1] "hxlineset"  "hxskel"     "neuron.obj" "neuron.ply" "qs"        
#> [6] "rds"        "rdsb"       "swc"        "vtk"       
if (FALSE) {
# write neuron to "myneuron.swc" in SWC format
write.neuron(Cell07PNs[[1]], file='myneuron.swc')
# write in SWC format, normalising the integer ids that label every node
# (this is required by some SWC readers e.g. Fiji)
write.neuron(Cell07PNs[[1]], file='myneuron.swc', normalise.ids=TRUE)
# write out "myneuron.swc" in SWC format withour the final extension
write.neuron(Cell07PNs[[1]], file='myneuron.swc')
# write out "myneuron.amiramesh" in Amira hxlineset format
write.neuron(Cell07PNs[[1]], format = 'hxlineset', file='myneuron.amiramesh')

# write out "myneuron.am" in Amira hxlineset format
write.neuron(Cell07PNs[[1]], format = 'hxlineset', file='myneuron')
}