kevinushey / timeit

Easy profiling of R functions
2 stars 0 forks source link

replications argument causes error #1

Open artemklevtsov opened 9 years ago

artemklevtsov commented 9 years ago

Hi.

Seems the replications argument causes error. For reproduce:

options(error = function() traceback(2))

library(timeit)
timeit(colMeans(iris[-5]), replications = 1)
traceback()

Testing script:

LANG=C Rscript --vanilla /tmp/test.R
Loading required package: microbenchmark
Running iteration 1 of 10 ...
Error in `$<-.data.frame`(`*tmp*`, "replications", value = 1) :
  replacement has 1 row, data has 0
Calls: timeit -> do_timeit -> $<- -> $<-.data.frame
5: stop(sprintf(ngettext(N, "replacement has %d row, data has %d",
       "replacement has %d rows, data has %d"), N, nrows), domain = NA)
4: `$<-.data.frame`(`*tmp*`, "replications", value = 1)
3: `$<-`(`*tmp*`, "replications", value = 1)
2: do_timeit(call_me, replications = replications, interval = interval,
       memory.profiling = memory.profiling, show.warnings = show.warnings,
       i = i)
1: timeit(colMeans(iris[-5]), replications = 1)
5: stop(sprintf(ngettext(N, "replacement has %d row, data has %d",
       "replacement has %d rows, data has %d"), N, nrows), domain = NA)
4: `$<-.data.frame`(`*tmp*`, "replications", value = 1)
3: `$<-`(`*tmp*`, "replications", value = 1)
2: do_timeit(call_me, replications = replications, interval = interval,
       memory.profiling = memory.profiling, show.warnings = show.warnings,
       i = i)
1: timeit(colMeans(iris[-5]), replications = 1)

R version:

$ R --version
R version 3.1.3 (2015-03-09) -- "Smooth Sidewalk"
Copyright (C) 2015 The R Foundation for Statistical Computing
Platform: x86_64-unknown-linux-gnu (64-bit)
kevinushey commented 8 years ago

Thanks -- it looks like the issue here is that when replications is so small in this case, no timing data is captured (because colMeans() is executed so quickly). In general, timeit does not handle expressions that execute very quickly all that well.