Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It is not a problem of <code>do.call</code>, but <code>substitute</code> <s>which evaluate by default in the global environment. So</s> you need to tell it in which environment substitution must occur. Here obviously in the local envir of func3.</p> <p>This should work:</p> <pre><code> do.call("curve",list(expr = substitute(my.func, env = parent.frame()))) </code></pre> <p><strong>Edit</strong> thanks Dwin</p> <p>As said in the comment substitute env Defaults to the current evaluation environment. So Why the code below works? The answer in the help of <code>substitute</code></p> <blockquote> <p>formal argument to a function or explicitly created using delayedAssign(), the expression slot of the promise replaces the symbol. If it is an ordinary variable, its value is substituted, unless env is .GlobalEnv in which case the symbol is left unchanged.</p> </blockquote> <p><code>env = parent.frame(n=1)</code> is equivalent to <code>.GlobalEnv</code>, that why the symbol (my.func) is left unchanged. So the correct answer would be :</p> <pre><code>do.call("curve",list(expr = substitute(my.func, env = .GlobalEnv))) </code></pre> <p>To test , I open new R session :</p> <pre><code>func1 &lt;- function (m, n) { charac &lt;- paste ("func2 &lt;- function(x)", m, "*x^", n, sep = "") eval(parse(text = charac)) return(func2) } func3 &lt;- function (m, n) { my.func &lt;- func1 (m, n) do.call("curve",list(expr = substitute(my.func,env = .GlobalEnv))) } </code></pre> <p>Than I call </p> <pre><code> func3(2,6) </code></pre>
    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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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