title: cbinding to a vector within function returning logical0 not a character vector as expected
body: <p>I created a function to run cross validation on whichever model I enter into it:</p>
  
  <pre><code># vectors to hold results
  master_modelname &lt;- vector()
  master_modelmea &lt;- vector()
  
  # model coefficients
  master_sink &lt;- attr(mini_kitchensink$terms,"term.labels")
  master_stepF &lt;- attr(stepF$terms,"term.labels")
  master_stepB &lt;- attr(stepB$terms,"term.labels")
  
  # folds
  myKfolds &lt;- function(preds, dataset, num_folds=5, dependant=c("loss")) {
  
    # create vectors for holding predictions and actuals from k folds iterations
    cv_prediction &lt;- data.frame()
    testsetCopy &lt;- data.frame()
    kmeas &lt;- vector()
    folds &lt;- createFolds(dataset[,dependant], k=num_folds)
  
    for ( f in folds ) {
      ktrain &lt;- dataset[-f,]
      ktest &lt;- dataset[f,]
      kmodel &lt;- lm(paste(dependant,"~", paste(preds, collapse="+"),sep=""), data=ktrain)
      predictions &lt;- predict(kmodel, interval="prediction", newdata=ktest)
      temp &lt;- as.data.frame(predictions)
      cv_prediction &lt;- rbind(cv_prediction, temp)
      testsetCopy &lt;- rbind(testsetCopy, ktest)
      errors &lt;- ktest[,dependant] - as.numeric(predictions[,"fit"])
      kmeas &lt;- c(kmeas,mean(abs(errors)))
    }
    master_modelname &lt;- c(master_modelname, "bla")
    master_modelmea &lt;- c(master_modelmea, mean(kmeas))
  }
  </code></pre>
  
  <p>After calling the function:</p>
  
  <pre><code>myKfolds(master_stepB, ptrain, num_folds=5)
  </code></pre>
  
  <p>It runs after about 10 minutes.</p>
  
  <p>But my vectors <code>master_modelname</code> and <code>master_modelmea</code> are empty.</p>
  
  <p>However, if I just highlight and run the last two lines of my function, it works, these two vectors now have values 'bla' and a single number which is <code>mean(kmeas)</code></p>
  
  <p>I have to "force run" the final two lines in the function to get expected results. So does this mean that for some reason the ast two lines of my function are not running for some reason?</p>