From thmsroh at gmail.com  Tue Jan 31 17:39:50 2017
From: thmsroh at gmail.com (Thomas Roh)
Date: Tue, 31 Jan 2017 10:39:50 -0600
Subject: [Rd] rnbinom Returns Error that says optional argument is missing
Message-ID: <CAOyPvYCF2rnQWe+h2-kPcbBQ7_NVxAePi0H-EJu8a_8F0jEMtg@mail.gmail.com>

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]]



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