title: R & list.files(): list.files will not work within function?
body: <p>I am using Rversion 3.03 on a Windows 7 OS and am trying to solve a problem. I am not sure if this is just me being stupid or if this is really a problem with my version of R. </p>
  
  <p><strong>Intitial problem</strong>: I have a folder with 300+ csv files and I need to specify a function that reads in a user-specified number of files. So my idea was to use the list.files function to give me a list of the csv's and then choose from this list rather than having to reformat the user input to match the csv filenames.</p>
  
  <pre><code>pm &lt;- function(directory, id = 1:332) {
  
  setwd("C:/Users/cw/Documents")
  setwd(directory)
  
  x &lt;- id[1] 
  x
  
  files &lt;- list.files() 
  
  #for (x in 1:length(id))
  #data[i] &lt;- read.csv(files[x], header=T) 
  #}
  }
  </code></pre>
  
  <p>pm("specdata", 25:30)</p>
  
  <p>So first I set the wd which works like a charm. Then I wanted to set x equal to the first element of id to obtain a starting point. Next I wanted to build a vector 'files' to choose the filenames from. </p>
  
  <p><strong>Real problem</strong>: if I run the 'pm'-function, R tells me that the object files does not exist. So am I doing sth wrong (obviously I am) and what? </p>
  
  <p>Thanks very much,
  C</p>