I have made a plan with drake_plan()
using the drake package.
here is a target I have made:
tables_weighted_pat = make_weights(
x = dat_pat$data,
struc = dat_pat$struc,
start_vars = start_vars,
display_values = dat_pat$display_values,
patient_data = TRUE,
label_dk = label_dk,
stratified = TRUE )
the code for the funcktion make_weights()
:
make_weights <-
function(x,
struc,
labels_dat,
strat_vars,
patient_data,
display_values,
label_dk = NULL,
stratified = FALSE) {
vars <-
select_included_vars(x = x, struc = struc)
group = c("age_5", "sex", "edu")
x <- calc_weights (x = x, group = group)
if (!patient_data) {
x[, weight := 1]
}
tmp <- make_denominator_filter_questions (
x = x, vars = vars, patient_data = patient_data, labels_dat = labels_dat, label_dk = label_dk)
names(tmp) <- vars$var
items_to_stratify <-
select_stratified_vars(x = x, struc = struc)$var
tot <- avg_over_unselected_vars(dat = tmp, items_to_stratify = items_to_stratify , labels_dat = labels_dat)
if (!stratified) {
return(tot)
}
tables_weighted <- map(strat_vars, function(i)
{
avg_over_unselected_vars(dat = tmp, strat_var = i, items_to_stratify, labels_dat)
})
names(tables_weighted) <- names(strat_vars)
tables_weighted [["total"]] <- tot
out <- format_tables (tables_weighted = tables_weighted, display_values = display_values, struc = struc, label_dk)
if (stratified == T)return(list(dat = out, weights = weights ))
return(out)
)
this code also includes homemade functions, but they are not important here, as I am sure they are not the ones who make the error.
when I run the drake_plan, I get this error message:
> target tables_weighted_pat
x fail tables_weighted_pat
Error: target tables_weighted_pat failed.
diagnose (tables_weighted_pat) $error$message:
first argument has length > 1
I dont understand what is wrong.... I hope I can get help - please tell me if I should add more details in the code - but I feel that the error occurs in the make_weights ()