[Rd] rnbinom Returns Error that says optional argument is missing

Thomas Roh thmsroh at gmail.com
Tue Jan 31 17:39:50 CET 2017

I am trying to reset the default arguments in the rnbinom function with the
following example code:

params <- c("size" = 1, "mu" = 1)
formals(rnbinom)[names(params)] <- params
rnbinom(n = 10)

It returns the following:

Error in rnbinom(n = 10) : argument "prob" is missing, with no default

If I set the defaults with this code:

params <- c("size" = 1, "prob" = .5)
formals(rnbinom)[names(params)] <- params
rnbinom(n = 10)

The function works correctly. The documentation specifies that you can set
mu or prob with size. I understand that the problem lies in default
arguments are evaluated as missing, but it seems unintentional that setting
"prob" and "size" defaults will actually evaluate.

Here is the function call:

function (n, size, prob, mu)


    if (!missing(mu)) {

        if (!missing(prob))

            stop("'prob' and 'mu' both specified")

        .Call(C_rnbinom_mu, n, size, mu)


    else .Call(C_rnbinom, n, size, prob)


Thomas Roh
thmsroh at gmail.com

	[[alternative HTML version deleted]]

More information about the R-devel mailing list