Closed lindsayplatt closed 8 years ago
legend()
Currently breaks everything that is not points because modify_legend takes diff arguments than set_legend_args did.
To do tomorrow so that it is no longer broken:
failing on abline and rect calls: fails at modify_legend >> call_arguments >> normal_arguments >> set_args >> function_args >> getFromNamespace
The following test passes when I replace NA with NAinteger, but that is not a new test. I'm wondering why it did not fail before. New package update maybe?
gs <- gsplot() %>%
points(x=1, y=2, legend.name="Points 1", pch=1, col="blue") %>%
points(x=3, y=4, legend.name="Points 2", pch=5, col="red") %>%
error_bar(3,4, y.high=0.2, y.low=0.3, legend.name="Errors", text.font=2) %>%
rect(2,3,2.5,4, col="blue", border="orange", lwd=3, density=15, legend.name="rectangle") %>%
legend(location="bottomright", bg="lightgrey")
expect_equal(gs$legend$legend.args$lwd[4], NA)
This one is failing somewhere in call_arguments >> normal_arguments >> set_args
gs <- gsplot() %>%
curve(sin(x), from=-2*pi, to=2*pi, legend.name="sin(x)") %>%
legend()
Error in eval(expr, envir, enclos) : could not find function "*"
this is really bizarre - the environment for the lazy_eval is null when you do something else w/ the dots
eg <- function(...){
print(names(list(...)))
lazyeval::lazy_eval(lazyeval::lazy_dots(...))
}
eg(from=2 * pi)
[1] "from"
Error in eval(expr, envir, enclos) : could not find function "*"
#vs comment out the `print`:
eg <- function(...){
#print(names(list(...)))
lazyeval::lazy_eval(lazyeval::lazy_dots(...))
}
eg(from=2 * pi)
$from
[1] 6.283185
not what I would expect to happen.
This is a majorly simplified example of what is happening w/ that test in your PR.
The lazy eval thing is something I don't understand. But the lazy dots things in curve aren't actually needed so that odd behavior can be avoided.
I think curve.gsplot
can be re-written as:
curve.gsplot <- function(object, expr, from=0, to=1, n=101, ..., legend.name=NULL, side=c(1,2)){
expr <- lazy(expr)
x <- seq(from, to, length.out=n)
y <- lazy_eval(expr, data.frame(x=x))
object <- lines(object, x=x, y=y, ..., legend.name=legend.name, side=side)
return(object)
}
That fixes the test issue you are running into and deals with the minor issues pointed out in #236
@jread-usgs added a fix for calling legend() without any legend.names. For curve, should we do something different for the n default? Like keep increment <- (arguments$to-arguments$from)/10000
this?
Oh, just noticed that n=101
is the actual default. I leave that be.
When n is specified is causes an error:
gs <- gsplot() %>%
curve(sin(x), from=-2*pi, to=2*pi, n=10, legend.name="sin(x)") %>%
legend()
gs
Error in function_args(package, name, object, ...) : object 'x' not found
Hmm - I can't tell where you modified the curve.R file. Is that in here?
@jread-usgs just pushed from local
@lindsaycarr all good to merge?
Yay! Just saw this :)
We'll need to be careful with capturing the dots in proper order to make sure we don't run into that null env issue: https://github.com/hadley/lazyeval/issues/61
Coverage decreased (-0.06%) to 70.327% when pulling 39d6204628935df98efab011f92917e94ae9b594 on lindsaycarr:master into fc80a58ae698939973c8bde55f4e49bb985dabed on USGS-R:master.