title: Call a R function in OpenCPU with file arguments
body: <p>I want to let a user call a custom R function with custom arguments, using a web-based interface. Uploading local files for use should be possible.</p>
  
  <p>I tried to implement this using <a href="https://www.opencpu.org/" rel="nofollow noreferrer">OpenCPU</a> which worked fine until now. The user's code is packed into a <code>ocpu.Snippet</code> and passed together with the arguments <code>args</code> into</p>
  
  <pre><code>ocpu.call(
      'do.call',
      {
          'what': snippet,
          'args': args
      },
      session =&gt; /* processing of return value and console output */
  );
  </code></pre>
  
  <p>This works fine for all argument types I've worked with so far.</p>
  
  <p>Now that I'm testing the upload of files, I have found out the following:</p>
  
  <ol>
  <li>The <a href="https://github.com/Y0hy0h/opencpu.js/blob/master/opencpu.js" rel="nofollow noreferrer">JavaScript wrapper</a> (forked to remove annoying alerts) only detects files if they are on the upmost level (like <code>snippet</code> and <code>args</code> in the example above). This means that since my <code>args</code> <em>contain</em> a file object (<code>args = { file: File }</code>) they are not detected when using the call above. However, calling <code>ocpu.call('read.csv', args, ...)</code> works, since now the wrapper detects <code>file: File</code>.</li>
  <li>OpenCPU <a href="https://www.opencpu.org/api.html#api-arguments" rel="nofollow noreferrer">only allows file uploads using <code>multipart/form-data</code></a>. As far as I have learned, a nested file as I have in my original call is not representable in this format.</li>
  <li>Instead of using <code>do.call</code> I could write a custom R function to use, which allows for some way of providing used files as "first-order" arguments and then somehow passes them to the provided function.</li>
  </ol>
  
  <p>So I'm stuck, since I don't know how to write such a function and I really wonder if there is better way to call a custom function and control its arguments remotely. Do you have any idea how to solve this?</p>