[R] Convert numerical value into function which returns numerical value

Rainer M Krug Rainer at krugs.de
Thu Apr 9 14:39:14 CEST 2015


Hi

I want convert, in a function, an argument from a numerical value to a
function which returns this value.:

My Code:

--8<---------------cut here---------------start------------->8---
dep <- 13
dep <- function() {dep}
dep
--8<---------------cut here---------------end--------------->8---

This is what I get:
#+RESULTS:
,----
| function(PAI) { dep }
`----

This is what I want
,----
| function(PAI) { 13 }
`----

I thought about using eval(dep), but this gives me the effectively the
same.

Is it possible to achieve what I want? I somehow have the feeling this
is not that easily possible, as the code in the function definition is
only evaluated when the function is evaluated.

I could obviously do something like

--8<---------------cut here---------------start------------->8---
dep <- 13
depVal <- dep
dep <- function() {depVal}
dep()
--8<---------------cut here---------------end--------------->8---

But is there a better solution? 

Thanks,

Rainer

-- 
Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation Biology, UCT), Dipl. Phys. (Germany)

Centre of Excellence for Invasion Biology
Stellenbosch University
South Africa

Tel :       +33 - (0)9 53 10 27 44
Cell:       +33 - (0)6 85 62 59 98
Fax :       +33 - (0)9 58 10 27 44

Fax (D):    +49 - (0)3 21 21 25 22 44

email:      Rainer at krugs.de

Skype:      RMkrug

PGP: 0x0F52F982
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 494 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20150409/6b756ac3/attachment.bin>


More information about the R-help mailing list