@@ -120,9 +120,9 @@ xyzmatrix.dotprops<-function(x, ...) x$points
120
120
121
121
# ' @method xyzmatrix default
122
122
# ' @param y,z separate y and z coordinates
123
- # ' @details Note that \code{xyzmatrix.default } can extract 3d coordinates from a
124
- # ' a \code{matrix} or \code{data.frame} that \bold{either} has exactly 3
125
- # ' columns \bold{or} has 3 columns named X,Y,Z or x,y,z.
123
+ # ' @details Note that \code{xyzmatrix} can extract or set 3d coordinates in a a
124
+ # ' \code{matrix} or \code{data.frame} that \bold{either} has exactly 3 columns
125
+ # ' \bold{or} has 3 columns named X,Y,Z or x,y,z.
126
126
# ' @rdname xyzmatrix
127
127
# ' @export
128
128
xyzmatrix.default <- function (x , y = NULL , z = NULL , ... ) {
@@ -159,8 +159,9 @@ xyzmatrix.igraph<-function(x, ...){
159
159
igraph :: get.graph.attribute(x , ' xyz' )
160
160
}
161
161
162
- # ' @description Assign xyz elements of neuron or dotprops object. Can also
163
- # ' handle matrix like objects with columns named X,Y,Z
162
+ # ' @description \code{xyzmatrix<-} assigns xyz elements of neuron or dotprops
163
+ # ' object and can also handle matrix like objects with columns named X, Y, Z
164
+ # ' or x, y, z.
164
165
# ' @usage xyzmatrix(x) <- value
165
166
# ' @param value Nx3 matrix specifying new xyz coords
166
167
# ' @return Original object with modified coords
@@ -177,10 +178,13 @@ xyzmatrix.igraph<-function(x, ...){
177
178
178
179
# ' @export
179
180
`xyzmatrix<-.default` <- function (x , value ){
180
- if (is.neuron(x )) x $ d [,c(" X" ," Y" ," Z" )]= value
181
- else if (is.dotprops(x )) x $ points [,c(" X" ," Y" ," Z" )]= value
182
- else if (all(c(" X" ," Y" ," Z" ) %in% colnames(x ))) x [,c(" X" ," Y" ," Z" )]= value
183
- else stop(" Not a neuron or dotprops object or a matrix-like object with XYZ volnames" )
181
+ xyzn = c(" X" ," Y" ," Z" )
182
+ if (is.neuron(x )) x $ d [,xyzn ]= value
183
+ else if (is.dotprops(x )) x $ points [,xyzn ]= value
184
+ else if (! any(is.na(matched_cols <- match(xyzn , toupper(colnames(x )))))) {
185
+ x [,matched_cols ]= value
186
+ }
187
+ else stop(" Not a neuron or dotprops object or a matrix-like object with XYZ colnames" )
184
188
x
185
189
}
186
190
0 commit comments