title: Package compilation and relative path
body: <p>I must be very confused. Have looked around but cannot find a suitable answer and have a feeling I am doing something wrong.</p>
  
  <p>Here is a minimalist example:
  My function <code>test</code> import a file from a folder and does subsequent analysis on that file. I have dozens of compressed files in the folder specified by <code>path = "inst/extdata/input_data"</code></p>
  
  <pre><code>test = structure(function(path,letter) {
    file = paste0(path, "/file_",letter,".tsv.gz")
    data = read.csv(file,sep="\t",header=F,quote="\"",stringsAsFactors=F)
  
    return(mean(data$var1))
  
  }, ex = function(){
    path = "inst/extdata/input_data"
    m1 = test(path,"A")
  })
  </code></pre>
  
  <p>I am building a package with the function in the folder <code>R/</code> of the package directory.</p>
  
  <p>When I set the working directory to the package parent and run the example line by line, everything goes fine. However when I check the package with <code>R CMD check</code> it gives me the following:</p>
  
  <pre><code>cannot open file 'inst/extdata/input_data/file_A.tsv.gz': No such file or directory
  Error in file(file, "rt") : cannot open the connection
  </code></pre>
  
  <p>I thought in checking and building the package the working directory is automatically set to the parent directory of the package (that in my case is <code>"C:/Users/yuhu/R/Projects/ABCDpackage"</code> but it seems not to be the case.</p>
  
  <p>What is the best practice in this case? I would avoid converting all data in <code>.rda</code> format and put it in the <code>data</code> folder as there are too many files. Is there a way to compile the package and set in the function example the relative working directory where the package is located? This would be helpful also when the package is distributed (therefore it should not be my own path) </p>
  
  <p>Many thanks for your help.</p>