Similar logic to https://stackoverflow.com/a/14502298/4868692, instead of constructing call itself, something that is a bit opaque, we utilize the well-known function do.call
.
[
is a function with variable number of arguments depending on x
.do.call
is typically used to call functions with constructed argumnets.dimget = function(x, dim, idx, drop = TRUE){
d = rep(list(TRUE), length(dim(x)))
d[[dim]] = idx
do.call(`[`, c(list(x), d, drop = drop))
}
Advantages:
quote
, bquote
or as.call
makes the code easier to read and understand even for simpletons like me. Otherwise, the code is de-facto identical.Disadvantages: