title: Define a tidyverse-function
body: <p>I have a data.frame <code>df</code> and I would like to do some checks on the data. If there's an error (e.g. missing values or non plausible values) I would like to make a list containing the id of the case and the type of error.</p>
  <pre><code># Define an empty data.frame
  errors &lt;- data.frame(id = numeric(),
                       message = character())
  
  # Function that stacks all the errors
  addErrorMessage(message){
    
    errors &lt;- rbind(errors,   )  # &lt;= what to do here?
    
  }
  
  df &lt;- data.frame(id = 1:7,
                   var1 = c(1, 2, 3, 3, 9, 4, 5),
                   var2 = c(&quot;A&quot;, &quot;A&quot;, &quot;B&quot;, &quot;C&quot;, NA, &quot;D&quot;, &quot;A&quot;))
  
  
  ########### List of checks ################
  # Check 1: var1 should be smaller than 5
  df %&gt;% filter(var1 &gt; 5) %&gt;%
    addErrorMsg(message = &quot;Value of var1 is 5 or greater&quot;)
  
  # Check 2: var2 should not be missing
  df %&gt;% filter(is.na(var2)) %&gt;%
    addErrorMessage(message = &quot;Value of var2 is missing&quot;)
  
  </code></pre>
  <p>My question is: How can I define a function <code>addErrorMessage()</code> that I can directly use in the tidyverse-workflow? I want to avoid to save the wrong cases to a temporary data.frame for each check and then stack this data.frame on the <code>errors</code>-data.frame using <code>rbind()</code>.</p>