I am trying to use the aggregate_key
function in the fable
package to create a hierarchical time series in a shiny flexdashboard. The below code works fine as long as I can hard code in the column name 'value'.
library(tidyverse)
library(tsibble)
library(fable)
library(fpp2)
agg_key <- cbind.data.frame(visnights, year=1900:1975) %>%
pivot_longer(NSWMetro:OTHNoMet, names_to=c("State", "Region"), names_sep=c(3)) %>%
as_tsibble(index=year, key=c(State, Region)) %>%
aggregate_key(State / Region, value=sum(value))
The problem comes because I'm using a flexdashboard input to get the column name so it comes in as the character string "value". I've tried to following to no avail.
#only repeating the last line in the pipe for brevity
aggregate_key(State / Region, value=sum(!!"value"))
aggregate_key(State / Region, value=sum(!!!"value"))
aggregate_key(State / Region, value=sum(as.name("value")))
aggregate_key(State / Region, value=sum(as_label("value")))
Please help me figure out how to pass a character string to this function.