title: Error in seq_len 2 arguments passed to 'seq_len' which requires 1 using foreach package in R?
body: <p>I am trying to run a for loop in R using parallel processing. I want to do a grid search on my ranger model to test different combinations in the model to see where I can best tune the model. In order for me to test different tuning methods I need to run a loop on the data here is the code:</p>
  <pre><code># Creating simulations    -------------------------------------------------
  hyper_grid &lt;- expand.grid(
    num.trees = c(300),
    quant = c(0.94,0.95),
    mtry = c(5,4),
    nodSize = c(50,40),
    num_weeks_train = c(6,5),
    rmse = NA
  );
  </code></pre>
  <p><strong>For loop</strong></p>
  <pre><code>foreach (j = seq_len(nrow(hyper_grid), .packages ='magrittr' )) %dopar% {
    print(j)
    # j = 1
    fit = BVR_model_sim(
      num_weeks_train = hyper_grid$num_weeks_train[j],
      data = df_base,
      quntile = hyper_grid$quant[j],
      start_week = 202001,
      end_week = 202016,
      ntrees = hyper_grid$num.trees[j],
      randMtry = hyper_grid$mtry[j],
      nodSize = hyper_grid$nodSize[j]
    )
    
    # hyper_grid$rmse[j] &lt;- fit$prediction_error
    
    sim_result &lt;- rbind(sim_result, cbind(hyper_grid[j, ], as.data.frame(fit$output)))
    
    print(sim_result)
  };
  </code></pre>
  <p><strong>Error</strong></p>
  <pre><code>Error in seq_len(nrow(hyper_grid), .packages = &quot;magrittr&quot;) : 
    2 arguments passed to 'seq_len' which requires 1
  </code></pre>
  <p><strong>My Non-Parallelized-loop that runs perfect fine but slow looks as such</strong></p>
  <pre><code>for (j in seq_len(nrow(hyper_grid)))  {
    print(j)
    # j = 1
    fit = BVR_model_sim(
      num_weeks_train = hyper_grid$num_weeks_train[j],
      data = df_base,
      quntile = hyper_grid$quant[j],
      start_week = 202001,
      end_week = 202016,
      ntrees = hyper_grid$num.trees[j],
      randMtry = hyper_grid$mtry[j],
      nodSize = hyper_grid$nodSize[j]
    )
    
    # hyper_grid$rmse[j] &lt;- fit$prediction_error
    
    sim_result &lt;- rbind(sim_result, cbind(hyper_grid[j, ], as.data.frame(fit$output)))
    
    print(sim_result)
  };
  </code></pre>