You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I was wondering if it would be nice to transform the following afun into a utility function. It would be relatively easy. I wanted to ask @edelarua@ayogasekaram if you think it would be nice to have and if you have seen someone requesting this kind of feature (I think it is done like this in a couple of cases in tern).
library(dplyr)
# Making a fake data similar to questioncf<-function(x) {
x<- as.character(x)
sapply(x, function(xx) switch(xx,
"n"= round(runif(1, 10, 30)),
"Mean"= rnorm(1, 2, 1),
NA))
}
df<- expand.grid(
Group= c("m1", "p"),
Analysis= c("An 1", "An 2"),
Metric= c("n", "Mean")
) %>%
mutate(Value= cf(Metric)) %>%
print()
library(rtables)
# Dummy analysis function to represent the data in "Value"# -> To understand the current solution please read these in this order:# * ?analyze# * ?additional_fun_params# * ?spl_contextspecial_afun<-function(x, .spl_context, .df_row){
# Extract the labels for each "analysis"labs<- as.character(x)
# Extract the column subset of datacol_sbset<-.spl_context$cur_col_subsetres_df<-.df_row[col_sbset[[length(col_sbset)]], ]
# Extract the values following the right labels ("Metric" here)metric_order<- sapply(labs, function(x) which(x==res_df$Metric))
res_lst<- as.list(res_df$Value[metric_order])
names(res_lst) <-labs# to be safe: add the labels# Set custom formatsres_fmt<- setNames(list("xx", "xx.x"), labs)
# Returning the list of results for one column at a time
in_rows(.list=res_lst, .formats=res_fmt)
}
basic_table() %>%
split_rows_by("Analysis") %>%
split_cols_by("Group") %>%
analyze("Metric", afun=special_afun) %>%
build_table(df)
The text was updated successfully, but these errors were encountered:
I was wondering if it would be nice to transform the following
afun
into a utility function. It would be relatively easy. I wanted to ask @edelarua @ayogasekaram if you think it would be nice to have and if you have seen someone requesting this kind of feature (I think it is done like this in a couple of cases intern
).The text was updated successfully, but these errors were encountered: