[Rd] Subsetting the "ROW"s of an object
h@wickh@m @ending from gm@il@com
Fri Jun 8 23:15:20 CEST 2018
On Fri, Jun 8, 2018 at 2:09 PM, Berry, Charles <ccberry using ucsd.edu> wrote:
>> On Jun 8, 2018, at 1:49 PM, Hadley Wickham <h.wickham using gmail.com> wrote:
>> Hmmm, yes, there must be some special case in the C code to avoid
>> recycling a length-1 logical vector:
> Here is a version that (I think) handles Herve's issue of arrays having one or more 0 dimensions.
> subset_ROW <-
> dims <- dim(x)
> index_list <- which(dims[-1] != 0L) + 3
> mc <- quote(x[i])
> nd <- max(1L, length(dims))
> mc[ index_list ] <- list(TRUE)
> mc[[ nd + 3L ]] <- FALSE
> names( mc )[ nd+3L ] <- "drop"
> Curiously enough the timing is *much* better for this implementation than for the first version I sent.
> Constructing a version of `mc' that looks like `x[i,,,,drop=FALSE]' can be done with `alist(a=)' in place of `list(TRUE)' in the earlier version but seems to slow things down noticeably. It requires almost twice (!!) as much time as the version above.
I think that's probably because alist() is a slow way to generate a
alist(x = ),
list(x = quote(expr = )),
check = FALSE
#> # A tibble: 2 x 5
#> expression min mean median max
#> <chr> <bch:tm> <bch:tm> <bch:tm> <bch:tm>
#> 1 alist(x = ) 2.8µs 3.54µs 3.29µs 34.9µs
#> 2 list(x = quote(expr = )) 169ns 219.38ns 181ns 24.2µs
(note the units)
More information about the R-devel