1

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 ()

Russ Tedrake
  • 4,703
  • 1
  • 7
  • 10
Hellihansen
  • 163
  • 6
  • Just a heads-up - since 2021 the `drake` package is superseded by `targets` ([manual](https://books.ropensci.org/targets/), + [transitioning](https://books.ropensci.org/targets/drake.html)) from the same author. – Donald Seinen Aug 15 '22 at 09:56
  • If you do stick with `drake`, I suggest you have a look at https://books.ropensci.org/drake/debugging.html#interactive-debugging. There are a bunch of ways to interactively debug the function while the pipeline is running. The simplest is to restart you R session, load your functions, call `debug(make_weights)`, and then run `drake::make()`. Then you will get a `Browse[1]>` prompt and can step through the function as described at https://adv-r.hadley.nz/debugging.html#browser. – landau Aug 15 '22 at 12:43
  • Hard to say what the specific error is without the function arguments needed to test your code (see https://stackoverflow.com/help/minimal-reproducible-example). – landau Aug 15 '22 at 12:43
  • What can I add to the question so it is easier for you to help me i dont undestand the link you send me - it does not specify how to define the function arguments :) – Hellihansen Aug 17 '22 at 10:26

0 Answers0