title: command ls with pattern in a function is not working in R
body: <p>I am trying following function: </p>
  
  <pre><code>srch = function(srchstr){
      print(ls(pattern=srchstr))
  }
  </code></pre>
  
  <p>While following works:</p>
  
  <pre><code>ls(pattern='ddf')
  [1] "ddf"         
  </code></pre>
  
  <p>Calling the function produces following output: </p>
  
  <pre><code>srch('ddf')
  character(0)
  </code></pre>
  
  <p>I tried following methods:</p>
  
  <pre><code>ss = srch('ddf')
  character(0)
  
  ss
  character(0)
  
  print(ss)
  character(0)
  
  unlist(ss)
  character(0)
  
  sapply(ss, print)
  named list()
  
  sapply(ss, cat)
  named list()
  
  cat(ss)
  </code></pre>
  
  <p>'cat(ss)' simply gives no output!</p>
  
  <p>Why is this happening &amp; how can this be corrected?</p>