Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better handling of repeated, identical expressions #5

Open
joshuaulrich opened this issue Feb 18, 2018 · 1 comment
Open

Better handling of repeated, identical expressions #5

joshuaulrich opened this issue Feb 18, 2018 · 1 comment

Comments

@joshuaulrich
Copy link
Owner

This was reported as olafmersmann#7.


If the same expression is passed into microbenchmark() twice, then the resulting error is not very helpful.

library(microbenchmark)
microbenchmark(1 + 1, 1 + 1)
## Error in `levels<-`(`*tmp*`, value = if (nl == nL) as.character(labels) else paste0(labels,  : 
  factor level [2] is duplicated

(On older versions of R, you get the warning duplicated levels in factors are deprecated).

I can't think of a good reason why you would want to include the same expression twice, so this usually means a copy and paste error. Consequently, you should throw a human-readable error or warning before the expressions are evaluated, explaining the problem. Some thing like

The same expression, 1 + 1, appears more than once.
@MichaelChirico
Copy link
Contributor

Just came across the same, proximally/somewhat unexpectedly:

microbenchmark(times = 10000L,
  2**20,
  2^20,
  bitwShiftL(1, 20)
)

Of course 2**20 parses as 2^20 (see substitute(2**20)), but still had a head tilt when I saw this error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants