How can you get a data function to fail silently?
I have a data function that takes some input (two columns) and does some aggregation and then returns a table. I'd like to set it up so that when the code in the function fails, it does does not output an error message. The function updates the data in a chart every time the user selects or deselects a filter. But the function will throw an error when you filter out all the data. The preferred response would be for the function to fail silently and leave the existing table as it were. Any help you could give me would be greatly appreciated.
company <- input.group dollars <- input.val output.tbl <- data.frame(comp=company , dollars=dollars) output.tbl2 <- aggregate(output.tbl$dollars, by=list(output.tbl$comp), FUN=sum, ordered=TRUE) colnames(output.tbl2) <- c("company", "total_orders") rownames(output.tbl2) <- NULL #Sort in descending order output.tbl3 <- output.tbl2[order(output.tbl2$total_orders, decreasing=TRUE),] output.tbl3$size_cat <- cut(output.tbl3$total_orders, c(-1000000, 50000, 100000, 250000, 500000, 1000000, 10000000000 ), labels=c("$0+", "$50k+", "$100k+", "$250k+", "$500k+", "$1m+" )) output.tbl3$order_slabs <- cut(output.tbl3$total_orders, c(-1000000, 50000, 100000, 250000, 500000, 1000000, 10000000000 ), labels=c("$0 to $50k", "$50k to $100k", "$100k to $250k", "$250k to $500k", "$500k to $1m", "$1m+" ))
One way i can think of is:
- loading the filtered data table as is
- load the output data table as another input
In your script, add a condition to check if (1) is empty, if it is, then skip the calculation and use (2) as output.
Downside is your script might not run automatically due to cyclic dependency.
Interested to hear other solutions.