title: How to collapse a list of characters into a single string in R
body: <p>There is a list which I would like to output into an excel file as a single string.
  I start with a list of characters.</p>
  
  <pre><code>  url="http://eutils.ncbi.nlm.nih.gov/entrez/eutils/efetch.fcgi?db=pubmed&amp;id=21558518&amp;retmode=xml"
    xml = xmlTreeParse(url,useInternal = T)
    ns &lt;- getNodeSet(xml, '//PublicationTypeList/PublicationType')  
    types &lt;- sapply(ns, function(x) { xmlValue(x) } )  
    types
  </code></pre>
  
  <p>Output is this:</p>
  
  <pre><code>[1] "Journal Article"                      "Multicenter Study"                    "Research Support, N.I.H., Extramural"
  [4] "Research Support, Non-U.S. Gov't"    
  </code></pre>
  
  <p>So in types - there is a list of characters
  Now I need to make into a single string.
  This is what I have so far but it is not optimal:</p>
  
  <pre><code> types_as_string = as.character(types[[1]])
        if (length(types) &gt; 1) for (j in 2:length(types))   types_as_string = paste(types_as_string,"| ",as.character(types[[j]]),sep="")
   types_as_string          
   [1] "Journal Article| Multicenter Study| Research Support, N.I.H., Extramural| Research Support, Non-U.S. Gov't"
  </code></pre>
  
  <blockquote>
    <p></p>
  </blockquote>
  
  <p>So I want to end up with a nice string separated by pipes or other separator. (the last code part - is what I want to re-write nicely). The pipes are important and they have to be properly done. </p>