0

The following code should not work, should it?

plot(1:10,1:10,main="",)

(There is an "illegal" comma at the end, right?)

3
  • 3
    You'll need to tag what language you're using here so that the right people can come look and answer. I'm sure its valid in some language somewhere and not in others. ;-) Commented Jul 21, 2014 at 13:29
  • Looks like MATLAB, or maybe R, but OP needs to clarify ASAP. Commented Jul 21, 2014 at 13:30
  • I do apologise - that's what happens when you only use one language! Commented Jul 23, 2014 at 8:09

1 Answer 1

1

The syntax of this statement is not illegal. R will use the parameter's default value if you provide an "empty" argument.

For example, the rnorm function takes three arguments. The latter two have default values:

rnorm(n, mean = 0, sd = 1)

The expressions

rnorm(10)
rnorm(10, )
rnorm(10, , )

are identical. However, if you add an additional comma (and therefore an additional argument), the command will fail:

rnorm(10, , , )
# Error in rnorm(10, , , ) : unused argument ()
Sign up to request clarification or add additional context in comments.

8 Comments

@DavidArenburg In the case of an numeric argument, the plot.default function is used. This function has many default values.
So why plot(,5) doesn't work but plot(5) does, while essentially it puts 5 in the y axis
@DavidArenburg The plot.default function has no default value for the first argument. If you omit the second argument, NULL is used by default. Have a look at the code of the function to see how this special case is treated.
Actually it more complicated than that, apparently the xy.coords comes in and tries to interpret it in a meaningful way, see Details in ?xy.coords (just found out it my self)
@DavidArenburg In xy.coords the default value for y is also NULL.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.