xyzmatrix gets coordinates from objects containing 3D vertex data

xyzmatrix<- assigns xyz elements of neuron or dotprops object and can also handle matrix like objects with columns named X, Y, Z or x, y, z.

xyzmatrix(x, ...)

# S3 method for default
xyzmatrix(x, y = NULL, z = NULL, ...)

# S3 method for character
xyzmatrix(x, ...)

# S3 method for neuron
xyzmatrix(x, ...)

# S3 method for neuronlist
xyzmatrix(x, ...)

# S3 method for shapelist3d
xyzmatrix(x, ...)

# S3 method for dotprops
xyzmatrix(x, ...)

# S3 method for hxsurf
xyzmatrix(x, ...)

# S3 method for igraph
xyzmatrix(x, ...)

# S3 method for mesh3d
xyzmatrix(x, ...)

xyzmatrix(x) <- value

# S3 method for character
xyzmatrix(x) <- value

# S3 method for neuron
xyzmatrix(x) <- value

# S3 method for dotprops
xyzmatrix(x) <- value

# S3 method for hxsurf
xyzmatrix(x) <- value

# S3 method for igraph
xyzmatrix(x) <- value

# S3 method for shape3d
xyzmatrix(x) <- value

# S3 method for neuronlist
xyzmatrix(x) <- value

# S3 method for shapelist3d
xyzmatrix(x) <- value

Arguments

x

object containing 3D coordinates

...

additional arguments passed to methods

y, z

separate y and z coordinates

value

Nx3 matrix specifying new xyz coords

Value

For xyzmatrix: Nx3 matrix containing 3D coordinates

For xyzmatrix<-: Original object with modified coords

Details

Note that xyzmatrix can extract or set 3D coordinates in a matrix or data.frame that either has exactly 3 columns or has 3 columns named X,Y,Z or x,y,z. As of Nov 2020, if these columns are character vectors, they will be correctly converted to numeric (with a warning for any NA values).

Getting and setting from character vectors

xyzmatrix can also both get and set 3D coordinates from a character vector (including a single data frame column) in which each string encodes all 3 coordinates e.g. "-1, 4, 10". It should handle a range of separators such as spaces, tabs, commas, semicolons and ignore extraneous characters such as brackets. Note that data are rounded by zapsmall in the replacement version to try to avoid cases where rounding errors result in long strings of digits to the right of the decimal place.

Replacement into character vectors introduces a number of corner cases when there are not exactly 3 numbers to replace in the target vector. We handle them as follows:

  • 0 values in target, >0 in replacement: use a default pattern

  • 1-2 values in target, same number of "good" values in replacement: insert those replacement value

  • 1-2 values in target, different number of values in replacement: use default pattern, give a warning

The default pattern will be the first entry in x with 3 numbers. Should there not be such a value, then the pattern will be "x, y, z".

See also

xyzmatrix

Examples

# see all available methods for different classes methods('xyzmatrix')
#> [1] xyzmatrix.character* xyzmatrix.default* xyzmatrix.dotprops* #> [4] xyzmatrix.hxsurf* xyzmatrix.igraph* xyzmatrix.mesh3d* #> [7] xyzmatrix.neuron* xyzmatrix.neuronlist* xyzmatrix.shapelist3d* #> see '?methods' for accessing help and source code
# ... and for the assignment method methods('xyzmatrix<-')
#> [1] xyzmatrix<-.character* xyzmatrix<-.default* xyzmatrix<-.dotprops* #> [4] xyzmatrix<-.hxsurf* xyzmatrix<-.igraph* xyzmatrix<-.neuron* #> [7] xyzmatrix<-.neuronlist* xyzmatrix<-.shape3d* xyzmatrix<-.shapelist3d* #> see '?methods' for accessing help and source code
# basic usage xyzmatrix(cbind(-1,2,3))
#> X Y Z #> [1,] -1 2 3
# character vector - useful e.g. when encoded in 1 column of a table str123="(-1,+2,3)" xyzmatrix(str123)
#> X Y Z #> [1,] -1 2 3
# replace xyzmatrix(str123) <- xyzmatrix(str123)/3 str123
#> [1] "(-0.333333,0.666667,1)"
xyzmatrix(str123) <- xyzmatrix(str123)*3 str123
#> [1] "(-0.999999,2,3)"
n=Cell07PNs[[1]] xyzmatrix(n)<-xyzmatrix(n) stopifnot(isTRUE( all.equal(xyzmatrix(n),xyzmatrix(Cell07PNs[[1]])) ))