title: Error: $ operator is invalid for atomic vectors with ols()
body: <p><code>sessionInfo()</code></p>
  
  <pre><code>## Platform: x86_64-w64-mingw32/x64 (64-bit)
  ## Running under: Windows 10 x64 (build 18363)
  ## 
  ## Matrix products: default
  ## 
  ## locale:
  ## [1] LC_COLLATE=English_United States.1252 
  ## [2] LC_CTYPE=English_United States.1252   
  ## [3] LC_MONETARY=English_United States.1252
  ## [4] LC_NUMERIC=C                          
  ## [5] LC_TIME=English_United States.1252    
  ## 
  ## attached base packages:
  ## [1] stats     graphics  grDevices utils     datasets  methods   base     
  ## 
  ## loaded via a namespace (and not attached):
  ##  [1] compiler_3.6.2  magrittr_1.5    tools_3.6.2     htmltools_0.4.0
  ##  [5] yaml_2.2.0      Rcpp_1.0.3      stringi_1.4.5   rmarkdown_2.0  
  ##  [9] knitr_1.26      stringr_1.4.0   xfun_0.11       digest_0.6.23  
  ## [13] rlang_0.4.2     evaluate_0.14
  
  library(broom,pos=4,quietly=TRUE)
  library(dplyr,pos=4,quietly=TRUE)
  library(rms,pos=4,quietly=TRUE)
  
  data(mtcars)
  df &lt;- within(mtcars, {
      vs &lt;- factor(vs, labels = c("V", "S"))
      am &lt;- factor(am, labels = c("automatic", "manual"))
      cyl  &lt;- ordered(cyl)
      gear &lt;- ordered(gear)
      carb &lt;- ordered(carb)
  })
  X &lt;- names(df)
  rsp &lt;- 1 # response variable
  Y &lt;- X[rsp] # response variable (mpg)
  Y1 &lt;- paste(Y,"~",sep="")
  X1 &lt;- X[-rsp] # omit response variable, (mpg)
  </code></pre>
  
  <p><strong>The following chunk is from Stack Overflow (23jul2017) Logistic regression: how to try every combination of predictors in R?.</strong></p>
  
  <pre><code>n &lt;- 3 # (all) n &lt;- length(X1) 
  out &lt;- unlist(lapply(1:n,function(n) combn(X1,n,FUN=function(row) paste0(Y1,paste0(row,collapse="+")))))
  mods = lapply(out,function(frml) lm(frml,data=df))
  tmp = bind_rows(lapply(out,function(frml) {
      a = glance(lm(frml,data=df))
      a$frml = frml
      return(a)
  }))
  
  tmp$r.squared &lt;- round(tmp$r.squared,4)
  tmp$adj.r.squared &lt;- round(tmp$adj.r.squared,4)
  res2 &lt;- with(tmp,data.frame(frml,r.squared,adj.r.squared,AIC,BIC))
  OrdAIC &lt;- res2[order(res2$AIC),]
  OrdAIC[1,]
  
  mod &lt;- ols(mpg~wt+qsec+am,data=df,x=T,y=T)
  </code></pre>
  
  <p><strong>works</strong></p>
  
  <pre><code>mod &lt;- ols(OrdAIC[1,1],data=df,x=T,y=T)
  </code></pre>
  
  <p><strong>produces Error: $ operator is invalid for atomic vectors
  What am I doing wrong? 
  How do I fix the code so that it works by reference rather then hard coding?</strong></p>