title: writing function for reading files from a directory in R
body: <p>I am trying to write a function to read files from a directory and then either print the head of the file or summary of the head of the file in R. My code is as below...</p>
  
  <pre><code>getmonitor &lt;- function(id, directory, summarize = FALSE) {
      if(id&gt;=1 &amp;&amp; id&lt;10) {
          te1 &lt;- paste("00",id,sep="")
          #print(te1)
      } else if(id&gt;10 &amp;&amp; id&lt;=99) {
          te1 &lt;- paste("0",id,sep="")
          #print(te1)
      } else {
          te1 &lt;- id
          #print(te1)
      }
  filename = paste(directory, te1, sep = "/")
  filename1 = paste(filename, "csv", sep = ".")
  filename1
  test &lt;- read.csv(file = filename1)
      if(summarize==TRUE) {
          test1 &lt;- summary(test)
      } else {
          test1 = test
      }
      return (test1)
  }
  </code></pre>
  
  <p>When i use this function without summarize option it works fine as below....</p>
  
  <pre><code>data &lt;- getmonitor(1, "specdata") 
  &gt; head(data) 
          Date sulfate nitrate ID
  1 2003-01-01      NA      NA  1
  2 2003-01-02      NA      NA  1
  3 2003-01-03      NA      NA  1
  4 2003-01-04      NA      NA  1
  5 2003-01-05      NA      NA  1
  6 2003-01-06      NA      NA  1
  </code></pre>
  
  <p>But when i use the summary option then i getting the output with all quotes around the lines as below...</p>
  
  <pre><code>data &lt;- getmonitor(101, "specdata", TRUE) 
  &gt; head(data) 
           Date          sulfate            nitrate                ID       
   "2005-01-01:  1  " "Min.   : 1.700  " "Min.   : 0.2490  " "Min.   :101  "
   "2005-01-02:  1  " "1st Qu.: 3.062  " "1st Qu.: 0.6182  " "1st Qu.:101  "
   "2005-01-03:  1  " "Median : 4.345  " "Median : 1.0500  " "Median :101  "
   "2005-01-04:  1  " "Mean   : 6.267  " "Mean   : 2.2679  " "Mean   :101  "
   "2005-01-05:  1  " "3rd Qu.: 7.435  " "3rd Qu.: 2.7825  " "3rd Qu.:101  "
   "2005-01-06:  1  " "Max.   :22.100  " "Max.   :10.8000  " "Max.   :101  "
  </code></pre>
  
  <p>I don't want any of the quotes for the lines. I even tried converting this into df but doesn't work. Where am i doing wrong?</p>