sjmgarnier / viridis

Colorblind-Friendly Color Maps for R
http://sjmgarnier.github.io/viridis
Other
294 stars 38 forks source link

err checks for begin & end args not correct #32

Closed mdscheuerell closed 8 years ago

mdscheuerell commented 8 years ago

It appears as though the error checking part of viridis() is incorrect. That is, the begin and end args both need to lie within [0,1], but this returns an error

> viridis(n=3,begin=0.2,end=1,option="D")
Error in viridis(n = 3, begin = 0.2, end = 1, option = "D") :
  begin and end must be in [0,1]

When I look at the function defn, here's the error check:

if (!(begin %in% c(0, 1)) | !(end %in% c(0, 1))) {
  stop("begin and end must be in [0,1]")
}

The problem is that this test only passes if begin or end are equal to 0 or 1, but not anything in between. I think you need something like

if (begin < 0 | begin > 1 | end < 0 | end > 1 | end < begin) {
  stop("begin and end must be in [0,1]")
}
sjmgarnier commented 8 years ago

@mdscheuerell This error was corrected in #31 but not pushed to CRAN yet (I wasn't careful enough when I accepted the PR that introduced this feature in the first place). I'll try to submit the corrected version to CRAN tomorrow. Sorry about this.

sjmgarnier commented 8 years ago

@mdscheuerell FYI, the bug fix was pushed to CRAN.