2

I'm a python guy and very new to R (so far, all I've done is copy-paste code and screen-shot the resulting, graph).

I would now like to actually learn the language so that I can draw useful plots (right now, I am trying to plot this).

In attempting my first plot, I came across this function call:

sets_options("universe", seq(from = 0, to = 25, by = 0.1))

Now, I would like to know if I can achieve the same result by calling

sets_options("universe", seq(0, 25, 0.1))

The help page for seq doesn't speak to this specifically (or I'm not reading it correctly), so I was hoping someone could shed some light on how R handles positional arguments

I tried calling the function that way in R and it worked (no syntax errors, etc), but I don't know how to test the output of that function, so I'm forced to ask here

Community
  • 1
  • 1
inspectorG4dget
  • 110,290
  • 27
  • 149
  • 241
  • 4
    The full details of how arguments are matched: http://cran.r-project.org/doc/manuals/r-release/R-lang.html#Argument-matching. Roughly, named arguments are matched first, then the remaining (passed) arguments are matched to the remaining (formal) arguments positionally. – Brian Diggs Oct 26 '13 at 04:31
  • Some comments on when to use named vs. position at http://adv-r.had.co.nz/Functions.html#calling-functions – hadley Oct 26 '13 at 12:42

2 Answers2

0

Calling sets_options() will display the current settings. From the following log, it seems that the positional arguments are treated as expected:

> sets_options("universe", seq(0,5,0.25))
> sets_options()
$quote
[1] TRUE

$hash
[1] TRUE

$openbounds
[1] "()"

$universe
 [1] 0.00 0.25 0.50 0.75 1.00 1.25 1.50 1.75 2.00 2.25 2.50 2.75 3.00 3.25 3.50 3.75 4.00 4.25 4.50 4.75 5.00

> sets_options("universe", seq(from=0,to=5,by=0.25))
> sets_options()
$quote
[1] TRUE

$hash
[1] TRUE

$openbounds
[1] "()"

$universe
 [1] 0.00 0.25 0.50 0.75 1.00 1.25 1.50 1.75 2.00 2.25 2.50 2.75 3.00 3.25 3.50 3.75 4.00 4.25 4.50 4.75 5.00
inspectorG4dget
  • 110,290
  • 27
  • 149
  • 241
  • 2
    Correct. Positional arguments are always valid in R and the order that is present in python is not in R. You can also define your function args in whatever order you want. – Justin Oct 26 '13 at 03:55
0

The question is what seq is doing with positional versus named objects. The way to address this looking at the ?seq page which lays out the named arguments and their order:

seq(from = 1, to = 1, by = ((to - from)/(length.out - 1)),
length.out = NULL, along.with = NULL, ...)

So seq(0, 25, 0.1) will be interpreted the same way as seq(from = 0, to = 25, by = 0.1) since the order is the same as name in Usage listing.

IRTFM
  • 258,963
  • 21
  • 364
  • 487