I'm trying to pass a set of modified arguments from a larger function to arguments in a nested function. This is an argument supplied from the larger function:
time_dep_covariates_list = c(therapy_start = "Start of Therapy",
                             therapy_end = "End of Therapy")
I have these sets of constant arguments:
    tmerge_args_1 <- alist(data1 = analytic_dataset, 
                     data2 = analytic_dataset, 
                     id = patientid, 
                     tstop = adv_dx_to_event, 
                     death_censor = event(adv_dx_to_event))
And I want to append these modified arguments to that argument list:
   tmerge_args_2 <- lapply(1:length(time_dep_covariates_list), function(x){
            tmerge_args <<- c(tmerge_args, alist('var' = tdc(var)) )
            paste0(names(time_dep_covariates_list[x])," = 
            tdc(",names(time_dep_covariates_list[x]), ")")
            })
 > tdc_args
 [[1]]
 [1] "therapy_start = tdc(therapy_start)"
 [[2]]
 [1] "therapy_end = tdc(therapy_end)"
I want to create a do.call that handles the arguments like so:
count_process_form <- do.call(tmerge, args = c(tmerge_args_1,
                                              tmerge_args_2)
That would be identical to the following:
tmerge(data1 = analytic_dataset, data2 = analytic_dataset,
       id = patientid, tstop = adv_dx_to_event, 
       therapy_start = tdc(therapy_start), therapy_end = tdc(therapy_end)
It works fine with tmerge_args_1 by itself, but as the args_2 are character and not language elements, I get this error:
Error in (function (data1, data2, id, ..., tstart, tstop, options)  : 
all additional argments [sic] must have a name:
How can I modify the list I'm creating for args_2 so they're stored as arguments that do.call can understand? Or am I approaching this all wrong?
Thanks!
Here is a reproducible example:
analytic_dataset= data_frame(patientid = sample(1:1000,5),
                         adv_dx_to_event = sample(100:200, 5),
                         death_censor = sample(0:1,5, replace = T),
                         therapy_start = sample(1:20,5),
                         therapy_stop = sample(40:100,5))
The below would be passed in from a function:
time_dep_covariates_list = c(therapy_start = "Start of Therapy",
                         therapy_end = "End of Therapy")
tmerge_args_1 <- alist(data1 = analytic_dataset, 
                   data2 = analytic_dataset, 
                   id = patientid, 
                   tstop = adv_dx_to_event, 
                   death_censor = event(adv_dx_to_event))
do.call(tmerge,tmerge_args_1) #this works 
tmerge_args_2 <- lapply(1:length(time_dep_covariates_list), function(x){
 tmerge_args <<- c(tmerge_args, alist('var' = tdc(var)) )
  paste0(names(time_dep_covariates_list[x])," = tdc(",names(time_dep_covariates_list[x]), ")")
})
do.call(tmerge,tmerge_args_1,tmerge_args_2) # this doesn't```
