title: R purrr capture input and outputs
body: <p>Maybe this is more like logging rather than just functional programming, but I was wondering if there was a more <code>purrr</code> like way to achieve a message of inputs and outputs/diagnostic messages.</p>
  
  <p>This is useful to me as I'd like to use <code>sparklyr</code> in production and have a log of job statuses of queries over partitions.</p>
  
  <pre><code>library(magrittr)
  
  # Helper to list input params with output
  helper = function(x, y, z) {
    c(query = x, params = y, z) 
  }
  
  # For single parameters
  log_results = function(param, functions, adjective) {
  
    # Cross the input vectors to apply each function to each parameter set
    crossed_args = purrr::transpose(purrr::cross2(param, functions))
    crossed_params = crossed_args[[1]] %&gt;% unlist
    crossed_function_names = crossed_args[[2]] %&gt;% unlist()
  
    # Parse to the query to wrap it with quietly
    parsed_functions = purrr::map(crossed_function_names, ~ adjective(eval(parse(text = .x))))
  
    # Tidy container for function calls
    df = dplyr::data_frame(function_name = crossed_function_names, f = parsed_functions, param = crossed_params)
    # Execute to get query results
    results_log = purrr::map2(df$f, df$param, ~ .x(.y))
  
    # Output results log as message
    purrr::pmap(.l = list(df$function_name, df$param, results_log), helper) %&gt;% str
  
  }
  </code></pre>
  
  <p>All this is doing is making a table of row-wise jobs to dispatch and returning the job with diagnostic messages. This is dumped to a log, so  if there was a failure, I can check which job failed.   </p>
  
  <pre><code>log_results_quietly = purrr::partial(log_results, adjective = purrr::quietly)
  
  &gt; log_results_quietly(c(-1, 3, 4, 5), c("exp", "log"))
  List of 8
   $ :List of 6
    ..$ query   : chr "exp"
    ..$ params  : num -1
    ..$ result  : num 0.368
    ..$ output  : chr ""
    ..$ warnings: chr(0) 
    ..$ messages: chr(0) 
   $ :List of 6
    ..$ query   : chr "exp"
    ..$ params  : num 3
    ..$ result  : num 20.1
    ..$ output  : chr ""
    ..$ warnings: chr(0) 
    ..$ messages: chr(0) 
   $ :List of 6
    ..$ query   : chr "exp"
    ..$ params  : num 4
    ..$ result  : num 54.6
    ..$ output  : chr ""
    ..$ warnings: chr(0) 
    ..$ messages: chr(0) 
  ...
  </code></pre>
  
  <p>I thought <code>invoke</code> might help, but I couldn't make it play nice with <code>quietly</code>.</p>
  
  <p>Any suggestions on how this could better be done are appreciated. Thanks</p>