Note that there are some explanatory texts on larger screens.

plurals
  1. POPass unevaluated commands to a function in R
    primarykey
    data
    text
    <p>I am a bit of an R novice, and I am stuck with what seems like a simple problem, yet touches pretty deep questions about how and when things get evaluated in R.</p> <p>I am using Rserve quite a bit; the typical syntax to get things evaluated remotely is a bit of a pain to type repeatedly:</p> <pre><code>RSeval(connection, quote(try(command))) </code></pre> <p>So I would like a function r which does the same thing with just the call: </p> <pre><code>r(command) </code></pre> <p>My first, naive, bound to fail attempt involved: </p> <pre><code>r &lt;- function(command) { RSeval(c, quote(try(command))) } </code></pre> <p>You've guessed it: this sends, literally, <code>try(command)</code> to my confused Rserve daemon. I want <code>command</code> to be <strong>partially</strong> evaluated, if that makes any sense -- i.e. replaced by what I typed as an argument, but <strong>without</strong> evaluating it locally.</p> <p>I looked for solutions to this, browsed throught the documentation for quote, substitute, eval, call, etc.. but I was not able to find something that worked. Either <code>command</code> gets evaluated locally, or not at all.</p> <p>This is not a big problem, I can type the whole damn <code>quote(try())</code> thing all the time; but at this point I am mostly curious as to how to get this to work!</p> <p>EDIT: More explanations as to what I want to do.</p> <ul> <li>In the text above, <code>command</code> is meant to be a call do a function, ideally -- i.e., not a character string. Something like <code>a &lt;- 3</code> or <code>assign("a", 3)</code> rather than <code>"a&lt;-3"</code> or <code>quote(a&lt;-3)</code>. I believe that this is part of what makes this tricky. It seems really hard to tell R not to evaluate this locally, but only send it literally. Basically I would like my function to be a bit like <code>quote()</code>, which does not evaluate its argument.</li> <li>Some explanation about my intentions. I wish to use Rserve frequently to pass commands to a remote R daemon. The commands would be my own (or my colleagues) and the daemon protected by firewall and authentication (and would not be run as root) -- so there is no worry of malicious commands being passed.</li> <li>To be perfectly honest, this is not a big issue, and I would be pretty happy to always use the <code>RSeval(c, quote(try()))</code>. At this point I see this more like an interesting inquiry into the subleties of R :-)</li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload