title: In R:How do I itearate through character strings in a loop?
body: <p>I'm trying to access character strings from a vector in a for-loop.</p>
  
  <p>I have a Corpus like this one:</p>
  
  <pre><code>library(tm)
  corpus = Corpus(VectorSource(c("cfilm,cgame,ccd","cd,film,cfilm")))
  </code></pre>
  
  <p>My goal is to get rid off all unnecessary "c" characters. Note, that this means I don't want to remove the c from cd, but ccd, cgame and so forth.</p>
  
  <p>I use this function, which takes in a corpus and removes a term with a second one.</p>
  
  <pre><code>toString = content_transformer(function(x,from,to)gsub(from, to, x))
  </code></pre>
  
  <p>So, for example, to replace cgame with game, I use</p>
  
  <pre><code>corpus = tm_map(corpus,toString,"cgame","game")
  </code></pre>
  
  <p>Now, I instead of repeating this line for all the terms, I'd like to use a loop that iterates to all the possible replacements using a vector with the relevant terms.</p>
  
  <pre><code>replace = c("game","film","cd")
  </code></pre>
  
  <p>I tried two approaches, but none of them would work:</p>
  
  <pre><code>for(i in replace){tm_map(corpus,toString,paste("c",get(i),sep=""),get(i))}
  </code></pre>
  
  <p>and</p>
  
  <pre><code>for(i in 1:length(replace)){tm_map(corpus,toString,paste("c",replace[i],sep=""),replace[i])}
  </code></pre>
  
  <p>In the first case R tells me that it can't find the object received by get(i): <code>Error in get(i) : object 'game' not found</code>.
  In the second, there is no error message, but nothing changes within the corpus.</p>
  
  <p>How can I query items within a vector as strings, so the for-loop would repeat for all the terms, what I did with <code>corpus = tm_map(corpus,toString,"cgame","game)</code></p>