title: Generic time-series backtesing/cross-validation with R
body: <p>I want to make some time-series evaluation in R. The process is usually to define a time lag and the evaluation frequency/periods, and for each evaluation period, train a model with the defined time lag and compute metrics for that period.</p>
  
  <p>For example, we have:</p>
  
  <ul>
  <li>Evaluation period size and interval <code>n</code></li>
  <li>Evaluation start at <code>b</code></li>
  <li>Time lag <code>l</code></li>
  </ul>
  
  <p>We train a model with points <code>1:b-l</code>, evaluate it on <code>b:b+n</code>. After that we train a model with points <code>1:b+n-l</code> and evaluate it on <code>b+n:b+2n</code> and etc, for <code>k</code> periods. It could vary a bit but that's the general spirit. So this is basically a sliding window for the evaluation data, but an increasing window for training data.</p>
  
  <p>This is illustrated in the answer to <a href="https://stats.stackexchange.com/questions/326228/cross-validation-with-time-series">this</a> question (the expanding window solution).</p>
  
  <p>How could I do this, preferably without loops and using the tidyverse and/or packages specific for time-series analysis?</p>