Daniel
Daniel

Reputation: 41

R function-- the default value does not work?

I am really new to R. Allow me to ask a beginner's question.

When I type p.adjust, for example, I can see the following. It seems that the argument method is p.adjust.methods by default. I tried to trace the code but when I typed something like:

match.arg(p.adjust.methods)

It says:

Error in match.arg(p.adjust.methods) : 'arg' must be of length 1

Why?

> p.adjust
function (p, method = p.adjust.methods, n = length(p)) 
{
    method <- match.arg(method)
    ...
}

Upvotes: 4

Views: 11047

Answers (1)

IRTFM
IRTFM

Reputation: 263301

The match.arg function does not work in interactive mode in its one argument form, since there is nothing to match to. That first argument is expected to be a length 1 character vector, and it is tested against the known methods _inside_the_function_:

> ?p.adjust
> p.adjust.methods
[1] "holm"       "hochberg"   "hommel"     "bonferroni" "BH"         "BY"         "fdr"       
[8] "none"     

(The first argument to p.adjust if you are using positional matching needs to be a vector of p-values.)

Upvotes: 7

Related Questions