title: source file specified as string in R
body: <p>I want to, programmatically, source all .R files contained within a given array retrieved with the <code>Sys.glob()</code> function.</p>
  
  <p>This is the code I wrote:</p>
  
  <pre><code># fetch the different ETL parts
  parts &lt;- Sys.glob("scratch/*.R")
  
  if (length(parts) &gt; 0) {
      for (part in parts) {
          # source the ETL part
          source(part)
  
          # rest of code goes here
          # ...
      }
  } else {
      stop("no ETL parts found (no data to process)")
  }
  </code></pre>
  
  <p>The problem I have is I cannot do this or, at least, I get the following error:</p>
  
  <pre><code>simpleError in source(part): scratch/foo.bar.com-https.R:4:151: unexpected string constant
  </code></pre>
  
  <p>I've tried different combinations for the <code>source()</code> function like the following:</p>
  
  <pre><code>source(sprintf("./%s", part))
  source(toString(part))
  source(file = part)
  source(file = sprintf("./%s", part))
  source(file = toString(part))
  </code></pre>
  
  <p>No luck. As I'm globbing the contents of a directory I need to tell R to source those files. As it's a custom-tailored ETL (extract, transform and load) script, I can manually write:</p>
  
  <pre><code>source("scratch/foo.bar.com-https.R")
  source("scratch/bar.bar.com-https.R")
  source("scratch/baz.bar.com-https.R")
  </code></pre>
  
  <p>But that's dirty and right now there are 3 different extraction patterns. They could be 8, 80 or even 2000 different patterns so writing it by hand is not an option.</p>
  
  <p>How can I do this?</p>