Skip to content

Raise error for showSelected2 aesthetic/parameter usage #215

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

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions R/z_animintHelpers.R
Original file line number Diff line number Diff line change
Expand Up @@ -173,13 +173,30 @@ hjust2anchor <- function(hjust){
}
}

#' @param params Named list of layer parameters
#' @return NULL if valid, stops with error if invalid showSelected variant found
validateShowSelectedParams <- function(params) {
if (is.null(params) || length(params) == 0 || is.null(names(params))) {
return(NULL)
}
param_names <- names(params)
# Match any parameter that starts with "showSelected" but is not "showSelected"
invalid_showSelected <- param_names[grepl("^showSelected.+", param_names)]
invalid_showSelected <- setdiff(invalid_showSelected, "showSelected")

if (length(invalid_showSelected) > 0) {
stop("Use of clickSelects and showSelected as aesthetics has been deprecated. Please use them as parameters instead.",
call. = FALSE)
}
}

#' Get all parameters for a layer
#'
#' @param l A single layer of the plot
#' @return All parameters in the layer
getLayerParams <- function(l){
params <- c(l$geom_params, l$stat_params, l$aes_params, l$extra_params)
validateShowSelectedParams(params)
if("chunk_vars" %in% names(params) && is.null(params[["chunk_vars"]])){
params[["chunk_vars"]] <- character()
}
Expand Down
4 changes: 2 additions & 2 deletions inst/examples/Climate-selected.R
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ viz$scatterNow <- ggplot()+
clickSelects="id", showSelected="time2",
data=climate, alpha=dot.alpha)+
geom_point(aes_string(x=var.names[[1]], y=var.names[[2]]),
showSelected2="id", showSelected="time2",
showSelected=c("id","time2"),
data=climate, colour="black", fill=selected.color)
for(var.name in var.names){
long.name <- long.names[[var.name]]
Expand Down Expand Up @@ -140,7 +140,7 @@ viz$scatterHere <- ggplot()+
data=climate, alpha=dot.alpha)
##+
geom_point(aes_string(x=var.names[[1]], y=var.names[[2]]),
showSelected2="time2", showSelected="id",
showSelected=c("time2","id"),
data=climate, color="black", fill="white")
viz$width <-
structure(as.list(rep(400, length(viz))),
Expand Down
3 changes: 1 addition & 2 deletions tests/testthat/test-compiler-plot-named-timexxx.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ viz <-
data=not.na)+
geom_text(aes(life.expectancy, fertility.rate, label=country),
data=not.na,
showSelected="country", showSelected2="year")+
showSelected=c("country", "year"))+
scale_size_animint(breaks=10^(5:9))+
make_text(WorldBank, 55, 9, "year"),

Expand Down Expand Up @@ -64,4 +64,3 @@ test_that("plot named time is NOT OK", {
animint2dir(bad, open.browser=FALSE)
}, "time option list needs ms, variable")
})

2 changes: 1 addition & 1 deletion tests/testthat/test-compiler-save-separate-chunks.R
Original file line number Diff line number Diff line change
Expand Up @@ -324,4 +324,4 @@ test_that("save separate chunks for non-spatial geoms with nest_order not being
must.have <- c("x", "xend", "y", "yend", "group")
expect_true(all(must.have %in% names(varied.data)))
unlink(out.dir, recursive = TRUE)
})
})
2 changes: 1 addition & 1 deletion tests/testthat/test-renderer1-WorldBank-NA.R
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,4 @@ test_that("bars render with time", {
num.vec <- as.numeric(at.mat[c("x", "width", "y", "height"), ])
expect_true(0 < ncol(at.mat))
expect_true(all(is.finite(num.vec)))
})
})