Displaying 2 results from an estimated 2 matches for "dim_illeg".
Did you mean:
dim_illegal
2014 Nov 24
1
Error "promise already under evaluation ..." with function(x, dim=dim(x))
...s overhead in using '::'.
Since I went through the effort of doing the benchmarking and find
faster solutions, I'm sharing the following:
> library("microbenchmark")
> x <- matrix(1:(80*80), nrow=80)
> # Not "legal", because it calls .Primitive().
> dim_illegal <- base::dim
> dim_R <- function(x) {
+ ns <- getNamespace("base")
+ dim <- get("dim", envir=ns, inherits=FALSE, mode="function")
+ dim(x)
+ }
> dim_R_memoized <- local({
+ dim <- NULL
+ function(x) {
+ if (is.null(dim)) {
+...
2014 Nov 24
0
Error "promise already under evaluation ..."
...1 771 2801.544 771 1156 1806225 1000 a
> dim_R(x) 5390 6930 8077.753 7315 8085 249069 1000 b
> dim_R_memoized(x) 1156 1926 2520.119 2310 2695 73528 1000 a
> dim_R_memoized_2(x) 385 771 1089.243 771 1156 20019 1000 a
> dim_illegal(x) 0 1 161.480 1 386 2311 1000 a
> sum(x) 10395 15784 16459.454 15785 16169 114333 1000 c
>
> So, my best shot on the original problem would now be to either use:
>
> dim2 <- function(x) dim(x)
> foo <- function(x, dim=dim2(x)) {...