hadley / strict

Make R a little bit stricter
235 stars 10 forks source link

Error if condition for control statements that have length != 1 #30

Open russellpierce opened 6 years ago

russellpierce commented 6 years ago

R can change its behavior for code like...

a <- 1:2
if (a == 1) {
  print("ok")
}

to be an error instead of the typical the condition has length > 1 and only the first element will be used warning. It seems like it might be in keeping with package:strict to throw that error. However, it looks like this would require setting an environmental variable...

Sys.setenv(`_R_CHECK_LENGTH_1_CONDITION_`="true")
a <- 1:2
if (a == 1) {
  print("ok")
}

What do you think, is setting that env var in scope for package:strict?