Skip to content
Prev 45668 / 63421 Next

Converting an environment to a list: mget vs. as.list

That is interesting!
That's a good point, but the first example was quite a bit larger, and
hence the impact of S3 dispatch slightly less:

env <- environment(plot)
names <- ls(env)

microbenchmark(
  as.list(env),
  as.list.environment(env),
  mget(names, env))

                     expr min lq median uq max neval
             as.list(env)  42 49     51 53 140   100
 as.list.environment(env)  39 44     46 48 117   100
         mget(names, env)  33 35     37 38  83   100

so mget still wins in that case.

Hadley

--
Chief Scientist, RStudio
http://had.co.nz/