[Rd] Error "promise already under evaluation ..."

Radford Neal radford at cs.toronto.edu
Mon Nov 24 19:46:02 CET 2014


> The above question still stands, but otherwise, I overlooked the most
> obvious solution:
> 
> dim_1 <- function(x) dim(x)
> 
> Unit: nanoseconds
>                   expr   min    lq      mean median    uq     max neval cld
>                 dim(x)     0     1    72.941      1     1    2696  1000 a
>           base::dim(x) 11549 13474 15105.950  14245 15399   60824  1000   c
>               dim_1(x)     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)) { dim }
> 
> or simply avoid the name clash via:
> 
> foo <- function(x, dimx=dim(x)) { dimx }


I think you'll find that baseenv()$dim(x) and .BaseNamespaceEnv$dim(x)
are about 25 times faster than base::dim(x).  This doesn't seem like
it should be necessary...

   Radford



More information about the R-devel mailing list