[Rd] patch for random.c

Berwin A Turlach statba at nus.edu.sg
Fri Feb 29 11:19:40 CET 2008


Dear all,

while looking for some inspiration of how to organise some code, I
studied the code of random.c and noticed that for distributions with
2 or 3 parameters the user is not warned if NAs are created while such
a warning is issued for distributions with 1 parameter.  E.g:

R version 2.7.0 Under development (unstable) (2008-02-29 r44639)

[...]

> rexp(2, rate=Inf)
[1] NaN NaN
Warning message:
In rexp(2, rate = Inf) : NAs produced
> rnorm(2, mean=Inf)
[1] NaN NaN

Surprisingly, the code for issuing warnings for distributions with 2 or
3 parameters is essentially there, but does not seem to be used.  The
attached patch rectifies this.  With the patch the above command produce
the following output:

> rexp(2, rate=Inf)
[1] NaN NaN
Warning message:
In rexp(2, rate = Inf) : NAs produced
> rnorm(2, mean=Inf)
[1] NaN NaN
Warning message:
In rnorm(2, mean = Inf) : NAs produced

Please ignore the patch if the code that was designed to produce the
warning had been removed on purpose.  

BTW, there are other places in the code were NAs can be created but no
warning is issued.  E.g:

> rexp(2, rate=numeric())
[1] NA NA
> rnorm(2, mean=numeric())
[1] NA NA

I wonder whether a warning should be issued in this case too.  

Best wishes,

	Berwin

-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: R-patch
Url: https://stat.ethz.ch/pipermail/r-devel/attachments/20080229/115e0cc2/attachment.pl 


More information about the R-devel mailing list