From: Sklyar, Oleg (London) <osklyar_at_maninvestments.com>

Date: Tue, 03 Nov 2009 11:27:58 +0000

})

**## THIS WILL BE WRONG!
**

outerfun3(x)

# output: length FUN=8001680; length DAT=8000022

R version 2.9.0 (2009-04-17)

x86_64-unknown-linux-gnu

Please consider the environment before printing this email or its attachments. The contents of this email are for the named addressees ...{{dropped:19}}

R-devel_at_r-project.org mailing list

https://stat.ethz.ch/mailman/listinfo/r-devel Received on Tue 03 Nov 2009 - 11:31:00 GMT

Date: Tue, 03 Nov 2009 11:27:58 +0000

mycall = function(x, fun) {

FUN = serialize(fun, NULL)

DAT = serialize(x, NULL)

cat(sprintf("length FUN=%d; length DAT=%d\n", length(FUN), length(DAT)))

invisible(NULL) ## return results of a call on a remote host with
FUN and DAN

}

## the function variant I will be passing into mycall

innerfun = function(z) z

x = runif(1e6)

## test run from the command line

mycall(x, innerfun)

# output: length FUN=106; length DAT=8000022

## test run from within a function

outerfun1 = function(x) mycall(x, innerfun)
outerfun1(x)

# output: length FUN=106; length DAT=8000022

## test run from within a function, where function is defined within

outerfun2 = function(x) {

nestedfun = function(z) z

mycall(x, nestedfun)

}

outerfun2(x)

# output: length FUN=253; length DAT=8000022

setGeneric("outerfun3", function(x) standardGeneric("outerfun3"))

## define a method

## test run from within a method

setMethod("outerfun3", "numeric",

function(x) mycall(x, innerfun))

outerfun3(x)

# output@ length FUN=106; length DAT=8000022

## test run from within a method, where function is defined within

setMethod("outerfun3", "numeric",

nestedfun = function(z) z mycall(x, nestedfun)

})

outerfun3(x)

# output: length FUN=8001680; length DAT=8000022

R version 2.9.0 (2009-04-17)

x86_64-unknown-linux-gnu

locale:

C

attached base packages:

[1] stats graphics grDevices utils datasets methods base

Please consider the environment before printing this email or its attachments. The contents of this email are for the named addressees ...{{dropped:19}}

R-devel_at_r-project.org mailing list

https://stat.ethz.ch/mailman/listinfo/r-devel Received on Tue 03 Nov 2009 - 11:31:00 GMT

*
This archive was generated by hypermail 2.2.0
: Tue 03 Nov 2009 - 12:40:19 GMT
*