Skip to content
Prev 199964 / 398502 Next

Is there a way to specify drop=FALSE as the global default?

Or you could write wrapper functions for [ and [<- that
add the drop=FALSE argument.  E.g.,
  SS <- function(x, ..., drop=FALSE) x[..., drop=drop] # 'Safe
Subscripting'
  `SS<-` <- function(x, ..., value) { x[...] <- value ; x }
Use them as
  SS(x, 1, i) # instead of x[1, i] 

Use grep (or codetools::walkCode) to make sure you don't
have any other calls to [ in your code.  (The ss<- is
there only so calls to [ on the left side of the assignment
don't attract grep's attention.)

S+ has a subscript2d() that does this and also lets
you use 2 subscripts on vectors (the 2nd must be 1
in that case, but you don't need to use if statements).
subscript2d doesn't even have the drop= argument - if
you want to make a vector from a one column matrix use
as.vector.

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com