title: Running a fine & working code through a loop doesn't work
body: <p>From the string:</p>
  
  <pre><code>"((VBD)(((JJ))(CC)((RB)(JJ)))((IN)((DT)(JJ)(NNP)(NNPS))))"
  </code></pre>
  
  <p>I needed the following: </p>
  
  <pre><code>"JJ", "RBJJ", "DTJJNNPNNPS", "JJCCRBJJ", "INDTJJNNPNNPS" "VBDJJCCRBJJINDTJJNNPNNPS"
  </code></pre>
  
  <p>(this was my earlier query on SO, which was solved by @Brian Diggs. Please refer to "R : how to differentiate between inner and innermost brackets using regex", if necessary)</p>
  
  <p>so I Used the following code:</p>
  
  <pre><code>library("plotrix")
  library("plyr")
  strr&lt;-c("((VBD)(((JJ))(CC)((RB)(JJ)))((IN)((DT)(JJ)(NNP)(NNPS))))")
  tmp &lt;- gsub("\\(([^\\(\\)]*)\\)",  '("\\1")', strr)
  tmp &lt;- gsub("\\(", "list(", tmp)
  tmp &lt;- gsub("\\)list", "),list", tmp)
  tmp &lt;- eval(parse(text=tmp))
  atdepth &lt;- function(l, d) {
  if (d &gt; 0 &amp; !is.list(l)) {
   return(NULL)
  }
   if (d == 0) {
   return(unlist(l))
   }
  if (is.list(l)) {
   llply(l, atdepth, d-1)
   }
   }
  
   pastelist &lt;- function(l) {paste(unlist(l), collapse="", sep="")}
   down &lt;- llply(1:listDepth(tmp), atdepth, l=tmp)
   out &lt;- if (length(down) &gt; 2) {
   c(unlist(llply(length(down):3, function(i) {
   unlist(do.call(llply, c(list(down[[i]]), replicate(i-3, llply), pastelist)))
   })), unlist(pastelist(down[[2]]))) 
   } else {
   unlist(pastelist(down[[2]]))
   }
   out &lt;- out[out != ""]
  </code></pre>
  
  <p>And I got what I wanted, But Is it not possible to use the above code through a loop to process multiple strings (strr etc.) at the same time? I roughly need a bunch of strings to be processed and collected in a file. I'm trying to include a loop, but always end up in having just the last string from the set of strings in the out file. How should I run the code through a loop? The string set below.</p>
  
  <pre><code>strr&lt;-c("(((((NNS))((IN)((NNS)(CC)(NNS))))((VBD)((PRP))((IN)((NN))))))", 
  
  "((((NNS))((VBD)((TO)(((NNP))((NNP))))((TO)((DT)(NNP))))))", 
  
  "((((IN)(((NNP))((NNP))))((NNP)(NNP)(NNPW)(NNP))((VBD)((IN)((DT)(JJ)(NN)(NN))))))"
  )
  </code></pre>