title: How to execute an unknown amount of function calls/"pipes" based upon data stored within a tibble?
body: <p>I'll try to make this example as reproducible and explicit as possible.</p>
  <p>To <strong>fully</strong> reproduce the code you'll need the following packages...</p>
  <pre><code>library(tidyverse)
  library(ompr)
  library(ompr.roi)
  library(ROI)
  library(ROI.plugin.glpk)
  </code></pre>
  <p>And, you'll need to create the following &quot;dummy&quot; set of data...</p>
  <pre><code>dummy_data &lt;-
    tibble(
      category = c(&quot;A01&quot;, &quot;A01&quot;, &quot;A01&quot;, &quot;A01&quot;, &quot;A05&quot;, &quot;A05&quot;, &quot;A05&quot;, &quot;A15&quot;, &quot;A15&quot;, &quot;A15&quot;, &quot;A15&quot;),
      unknown = c(&quot;w&quot;, &quot;b&quot;, &quot;c&quot;, &quot;l&quot;, &quot;w&quot;, &quot;b&quot;, &quot;c&quot;, &quot;w&quot;, &quot;b&quot;, &quot;c&quot;, &quot;o&quot;),
      known = c(388610, 7760, 94970, 129931, 366472, 360477, 82212, 128021, 114379, 72185, 32807),
      known_sum = c(1470189, 1470189, 1470189, 1470189, 1110194, 1110194, 1110194, 831287, 831287, 831287, 831287)
    )
  </code></pre>
  <p>My goal is use the OMPR package (mixed linear programming) to back-solve for a set of unknown factors based on an equation and some bounds/constraints which depend on data stored in the &quot;dummy_data&quot; tibble. I managed to quickly use the OMPR package to get the following example working through &quot;manually inputting&quot; all the necessary information from the dummy data. Below is the example for <strong>only</strong> the first category (A01)...</p>
  <pre><code>model &lt;-
    MILPModel() %&gt;%
      add_variable(w, lb = 1.8, ub = 2.8, type = &quot;continuous&quot;) %&gt;%
      add_variable(b, lb = 2.0, ub = 3.0, type = &quot;continuous&quot;) %&gt;%
      add_variable(c, lb = 1.1, ub = 1.8, type = &quot;continuous&quot;) %&gt;%
      add_variable(l, lb = 1.3, ub = 1.7, type = &quot;continuous&quot;) %&gt;%
      set_objective(388610*w+ 7760*b+ 94970*c+ 129931*l, &quot;min&quot;) %&gt;%
      add_constraint((388610*w+ 7760*b+ 94970*c+ 129931*l) == 1470189) %&gt;%
      solve_model(with_ROI(solver = &quot;glpk&quot;))
  
  </code></pre>
  <p>Now, the goal is to create an identical model for each &quot;category&quot; (i.e. A05, A15, and any other potential Axx), not just A01 as shown above. I could easily create 'model2' and 'model3' then manually input all the numbers. Removing the &quot;l&quot; variable for A05, and then adding a new &quot;o&quot; variable in for A15 (with its own specific bounds).</p>
  <p>However, this doesn't feel tidy, it's a lot of manual work, and it quickly becomes increasingly unsustainable as the number of categories/variables increases.</p>
  <p><strong>Is there a tidy-way to step through the dummy data set (perhaps using a group_map on &quot;category&quot;) where the mapping function creates a distinct model (as manually demonstrated above) but for every category - basing the model parameters on the unique set of variables/numbers present within the dataset for each category?</strong></p>
  <ul>
  <li>Creating only the variables shown for that category (i.e. w, b, c, l for A01; w, b, c for A05; w, b, c, o for A15)</li>
  <li>Attribute the correct &quot;known&quot; numbers within the set_objective and add_constraint calls.</li>
  <li>Attribute the correct &quot;known_sum&quot; number to the end (RHS) of the add_constraint call.</li>
  </ul>
  <p>I've tagged this question with rlang/metaprogramming because it feels  to me that I'm moving towards &quot;creating code using code&quot; to solve this problem (using quo, eval, etc.). However, I am completely naïve/inexperienced in that part of R-programming, and I'm bullish that there might be a much simpler way to solve this problem using a less-manual (and more-tidy) methodology!</p>
  <p>Appreciate any thought/assistance you might thrown my way in advance!</p>
  <p>Cheers,
  Troy</p>