title: Error in parse(text = x, keep.source = FALSE) : <text>:2:0: unexpected end of input 1: OffenceAgainst ~ ^
body: <p>I am trying to loop over a list of character vectors and use other functions to form linear models and calculate values for me:</p>
  
  <pre><code>all_model_error&lt;-function(explan_vars,depvar,dataset1,dataset2)
  {
   x&lt;-list() 
   model_combinations&lt;-all_models(explan_vars)
    for(i in 1:length(model_combinations))
    {
  
      x[[i]]&lt;-error_rates(model_combinations[[i]],depvar,dataset1,dataset2)
  
  
    }
   return(x)
  
  }
  </code></pre>
  
  <p>However when I run this function I get this error in parse. <code>parse()</code> is not used in any function within this function, and I am confused as to why I am receiving this error.</p>
  
  <p>The underlying functions are defined as such:</p>
  
  <pre><code>gen_formula&lt;-function(depvar,explan_vars)
  {
  
    reg_form&lt;-as.formula(paste(depvar,"~",paste(explan_vars,collapse = "+")))
  
    return(reg_form)
  
  }
  </code></pre>
  
  <p>This just returns your input in a form that the lm() function takes.Then:</p>
  
  <pre><code>error_rates&lt;-function(indvars,explan_vars,dataset1,dataset2)
  {
    reg_results&lt;-lm(gen_formula(depvar,explan_vars),data=dataset1)
    summary(reg_results)
  
    df_training&lt;-dataset1 %&gt;%
      add_residuals(reg_results) %&gt;%
      summarize(error_rate=mean(resid^2))
    training_error&lt;-df_training[1,1]
  
    df_test&lt;-dataset2 %&gt;%
      add_residuals(reg_results) %&gt;%
      summarize(error_rate=mean(resid^2))
    test_error&lt;-df_test[1,1]
  
  
    return(c(test_error,training_error))
  
  }
  </code></pre>
  
  <p>this just calculates the error of the model against your test and training data.
  then:</p>
  
  <pre><code>name_from_bin&lt;-function(b,vars)
  {
    return(vars[as.logical(b)])
  }
  
  
  
  all_models&lt;-function(variables)
  {
  
    k&lt;-length(variables)
  
    bin_vec&lt;-rep(list(0:1),k)
  
    bin_mat&lt;-expand.grid(bin_vec)
  
    list_of_RHS&lt;-list()
  
    for(i in 1:nrow(bin_mat))
    {
      list_of_RHS[[i]]&lt;-name_from_bin(bin_mat[i,],variables)
  
  
  
    }
    return(list_of_RHS)
  }
  </code></pre>
  
  <p>These functions are used to create a matrix of all possible combinations of the number of variables on which to base a model. Then it returns these character vectors as a list, of every possible combination of variables.</p>
  
  <p>I want to run all_model_error to find the error_rates() of all_models(). The underlying functions perform the task I want them to, and dont incude parse() which is why I'm confused with the error.</p>
  
  <p>I am running all_model_error(explan_vars,depvar,crime_weather_1,crime_weather_2) and getting this error.
  Where depvar is a single variable <code>OffenseAgainst</code> in my dataset, and explan_vars is a vector of 14 variables in the dataset. Crime_weather_1 and 2 are training and test datasets.</p>