I started by creating a tidyeval function that I can use to do least-squares fitting and apply business rules. I wanted it to be generic, so I specify which columns are the data data inputs for the model. It returns a tibble with the parameters of the fitted model:
fitPL <- function(data, conc, signal) {
conc <- enquo(conc)
signal <- enquo(signal)
#
# calculations here using !!conc and !!signal
# ...
#
return(ti.res)
}
This now works perfectly well if I call it using do(), given that Condition, Concentration and Result are columns of ti.data:
This of course gives an error because 'Concentration' does not exist to the future_map_dfr() call. But it also gives an error if I pass the column name as a character value, because then fitPL tries to do its calculations using the character value as its (only) input.
Do I need to wrap the column parameters some way? Or do I need to rewrite fitPL so that it also (?) accepts character inputs? Can I have it both ways (i.e. passing these parameters with or without quotes)?
I'm really keen to hear a tidyeval expert on this one, because the way I'd read enquo() being explained, it uses "black magic" to retrieve the expression originally passed by the user. I have to wonder how (if) that can still happen when enquo() is being called in a potentially entirely different R process from the original expression.
@Emmanuel, have you tested this with purrr::map_dfr() rather than do()? It might help to rule out any other syntactical problems
Since future_map has all the functionality of map you should be able to just replace one with the other. This assumes that you are returning a tibble with fitPL
BTW, I also managed to get my original syntax to work by making two changes: Using ensym() instead of enquo() inside fitPL() to encapsulate the parameters, and passing the parameters as character values. (I don't pretend to fully understand why, but I guess it has something to do with enquo() retaining a reference to the original environment, while ensym() does not.)
However, the answer of tbradley is the better solution. It has the advantage of retaining all grouping columns, while in my original code I could only split on one column.