How can I knit rmd with params and choose the multiple select input as input for group by?
I'm trying to create an rmd report with params.
---
...
output:
html_document:
params:
features:
label: features
value: ""
input: select
multiple: TRUE
choices: [blue, red, green, yellow]
---
Then I want to use the features as grouping variables.
df %>%
group_by(params$features) %>%
summarize(x = sum(x))
But the but when I print them out
params$features
## [1] "blue" "red" "green" "yellow"
...
And this is the error code
Quitting from lines 65-74 (clustern.rmd)
Error: Problem adding computed columns in `group_by()`.
x Problem with `mutate()` input `..1`.
ℹ `..1 = params$features`.
ℹ `..1` must be size 1163210 or 1, not 3.
...
I'm sure it's not that hard to solve but I searched succesless the web :/
I hope someone can solve this, thx!!
As these are character elements, an easier option is to use across
within group_by
library(dplyr)
df %>%
group_by(across(all_of(params$features))) %>%
summarise(x = sum(x, na.rm = TRUE))