Adding many flags to R Manipulate as a list / vector

I use {manipulate} to add multiple graphs to the graph - one for each row that is drawn. Since the required number is not predefined, I am trying to figure out a way to pass all the flags as a vector or list to the manipulate function. The documentation seems to suggest something:

to manipulate ( _expr , ...)

_expr: expression to evaluate.

...: one or more named control arguments (e.g., slider, collector, checkbox, or button), or a list containing named controls.

I think the solution will be to pass a list of as many flags as possible. But how exactly should this be done?

+4
source share
1 answer

The following example should do what you want:

 # Define function for ploting example <- function(...){ plot(cars) i <- 1 for (my.control in list(...)) { if (my.control) abline(0, i) i <- i+1 } } # Define your controls custom.args <- list() for (i in 1:5) { custom.args <- append(custom.args, list(checkbox(FALSE, paste("Ceckbox", i)))) } names(custom.args) <- paste("checkbox", 1:5, sep="") # Pass everything to manipulate library(manipulate) manipulate( eval(parse(text=sprintf('example(%s)', paste(names(custom.args), collapse=",")) )), custom.args) 

I don't know if there is a cleaner way to pass control values ​​to the build function, but at least it works.

+1
source

Source: https://habr.com/ru/post/1484500/


All Articles