"Missing parameter, no default value"-- in the R language Self-coding function, the error is reported if the parameter has no input value.
1. Questions
For example:
> My.func
My.func<-function (p) {
Print ("TEST is ok!")
Print (P)
}
> My.func ()
[1] "TEST is ok!"
Error in print (p):
Evaluating the ' x ' parameter when selecting a method for the ' print ' function error: Errors: Missing parameter ' P ' and no default value
2. Analysis
What about this? Is it possible to add null values as in the Java language? For example:
My.func<-function (p) {
Print ("TEST is ok!")
if (Is.null (p))
Print ("p value is null.")
Else
Print (P)
}
The answer is no. This is really not the same as other object-oriented languages like Java.
So how to solve it?
3. Solve
The answer is to add the default parameters, that is, in the R language, there are no indeterminate parameters to be allowed.
Examples of improvements:
My.func<-function (p=1) {
Print ("TEST is ok!")
Print (P)
}
Run:
> My.func ()
[1] "TEST is ok!"
[1] 1
>
After you set the default value, it works even if you do not enter a parameter.
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
R language-missing parameters and no default values