Hello list,

I have the following scenario:

f1 <- function(a)
{
     .... # doing things; may need 'a', but does not change 'a'.

     g <- function(x)
     {
          sum(x + a)    # Say. Use 'a'; does not change 'a'.
     }

     optimize(f = g, lower = 0, upper = 1)
}


f2 <- function()
{
    b <- runif(100000000000)   # Create big object.

    f1(a = b)
}


My main concern is to reduce copying of the big object 'a'. Questions:

(1) In f1, 'a' never appears on the LHS of assignment. Is it passed by value
or by reference? Say the situation is simpler and more general: no
optimization call in f1.

(2) Is there any difference, as far as copying of the big 'a' is concerned,
if 'g' is changed to
   g <- function(x, b)  { sum(x + b) }
and called by
    optimize(f = g, lower = 0, upper = 1, b = a)

(3) Is 'a' passed into the C optimization function one-off, or again and
again across the C-R interface?

(4) Does it help if I remove the argument 'a' of 'f1', and let 'g' look for
it (of course it should be referred to as 'b' now) directly in the
environment of 'f2'?

(5) Any suggestions?

Many thanks for your help!

Zepu

        [[alternative HTML version deleted]]

______________________________________________
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel

Reply via email to