[R] Evaluation "conflict" in combination of replicate() and rexp()as variable inside a function

Gerrit Eichner Gerrit.Eichner at math.uni-giessen.de
Fri May 23 13:53:52 CEST 2008


Dear userRs,

"playing around" with combinations of replicate() and random number 
generating functions inside a self-defined "wrapper" function I encounterd 
a puzzling behaviour.

The following are intentionally simple (and rather nonsense-) examples to 
isolate the relevant aspects. Please, note the seemingly "inconsistent" 
behaviour for the second call of rdistr() (with distr = rexp) for which I 
have not found any explanation (yet):

> rdistr <- function( distr, ...) replicate( 1, distr( n = 1, ...))

> rdistr( distr = rnorm)
[1] -0.8889223

> rdistr( distr = rexp)
[1] NaN
Warning message:
In distr(n = 1, ...) : NAs produced

> rdistr( distr = runif)
[1] 0.8444856


Trying to discover the reason for this observation, I looked into the code 
of replicate() and realized that this seems to be an issue of evaluation 
schemes (and maybe also of variable scoping), but I didn't delve deeper 
into it, yet. Can anybody more competent enlight me or give me a hint 
where to search, please? Thank you!

  Best regards  --  Gerrit

PS:

> sessionInfo()
R version 2.6.2 (2008-02-08)
x86_64-unknown-linux-gnu

locale:
LC_CTYPE=de_DE.UTF-8;LC_NUMERIC=C;LC_TIME=de_DE.UTF-8;LC_COLLATE=de_DE.UTF-8;LC_MONETARY=de_DE.UTF-8;LC_MESSAGES=de_DE.UTF-8;LC_PAPER=de_DE.UTF-8;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=de_DE.UTF-8;LC_IDENTIFICATION=C

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

loaded via a namespace (and not attached):
[1] rcompgen_0.1-17


---------------------------------------------------------------------
AR Dr. Gerrit Eichner                          Mathematical Institute
gerrit.eichner at math.uni-giessen.de   Justus-Liebig-University Giessen
Tel: +49-(0)641-99-32104          Arndtstr. 2, 35392 Giessen, Germany
Fax: +49-(0)641-99-32029               http://www.math.uni-giessen.de



More information about the R-help mailing list