-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcalc_set_metrics.R
More file actions
65 lines (44 loc) · 2.07 KB
/
Copy pathcalc_set_metrics.R
File metadata and controls
65 lines (44 loc) · 2.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
args = commandArgs(trailingOnly = TRUE)
library(parallel)
if (length(args) != 1) {
stop("the calc_set_metrics.R script requires exactly one argument: name of run config file ... thank you. goodbye.")
}
source(args[1])
run_name = gsub(".R", "", args[1])
system(paste0("mkdir -p results/", run_name))
# set metrics
mclapply(set_metrics, function(metric_) {
source(paste0("utilities/",
metric_,
".R"))
this_function = match.fun(metric_)
mclapply(set_group_by_vars,
function(gv_) {
gv_ %<>% strsplit(",") %>%
unlist
entities %<>%
group_by_se(gv_)
group_by_vars_vals = entities[,gv_] %>%
unique
group_index = group_indices(entities)
entities %<>% cbind(group_index = group_index) %>%
ungroup %>%
as.data.frame
indexed_group_by_vars_vals = entities[,c("group_index", gv_)] %>% unique
indexed_group_by_vars_vals_strings = sapply(1:nrow(indexed_group_by_vars_vals),
function(x) toString(indexed_group_by_vars_vals[x,-1])) %>% gsub(", ", "_", .)
this_metric_vals = mclapply(1:nrow(indexed_group_by_vars_vals),
function(j) this_function(entities[group_index == indexed_group_by_vars_vals[j,"group_index"], ])
mc.cores = 1)
this_metric_vals %<>% as.data.frame
names(this_metric_vals) = metric_
this_metric_vals %<>% cbind(indexed_group_by_vars_vals[,-1])
write.csv(this_metric_vals, paste0(results_base_dir,
"/",
run_name,
"/",
metric_,
".csv"),
row.names = FALSE)},
mc.cores = 1)},
mc.cores = 1)