A.R.
A.R.

Reputation: 15704

R seq function too many arguments?

I am getting an error that I don't really understand at all. I was just messing around with generating some sequences, and I came across this problem:

This should create a sequence of 50 numbers.

seq.int(from=1,to=1000,by=5,length.out=50)

But if I enter this in the console I get the error message:

Error in seq.int(from = 1, to = 1000, by = 5, length.out = 50) :
too many arguments

If I look at the help (?seq), in the Usage section there is this line in there which makes it seem as though I called the function correctly, and it allows this many number of arguments:

seq.int(from, to, by, length.out, along.with, ...)

So what the heck is going on? I am I missing something fundamental, or are the docs out of date?

NOTE The arguments I am providing to the function in the code sample are just for sake of example. I'm not trying to solve a particular problem, just curious as to why I get the error.

Upvotes: 1

Views: 5246

Answers (2)

A.R.
A.R.

Reputation: 15704

No, there is nothing fundamental to the R language that I was missing that was the source of the problem. The problem is that the documents, at least at time of writing, are misleading and/or incorrect.

Upvotes: -1

MichaelChirico
MichaelChirico

Reputation: 34763

It's not clear what you expect as output from this line of code, and you're getting an error because R doesn't want to resolve the contradictions for you.

Here is some valid output, and the line of code you'd use to achieve each. This is a case where you need to decide for yourself which approach to use given the task you have in mind:

Override length.out

  [1]   1   6  11  16  21  26  31  36  41  46  51  56  61  66  71  76  81  86
  ...
[199] 991 996

#via:
seq.int(from=1,to=1000,by=5)

Override by

 [1]    1.00000   21.38776   41.77551   62.16327   82.55102  102.93878  123.32653
 [8]  143.71429  164.10204  184.48980  204.87755  225.26531  245.65306  266.04082
[15]  286.42857  306.81633  327.20408  347.59184  367.97959  388.36735  408.75510
[22]  429.14286  449.53061  469.91837  490.30612  510.69388  531.08163  551.46939
[29]  571.85714  592.24490  612.63265  633.02041  653.40816  673.79592  694.18367
[36]  714.57143  734.95918  755.34694  775.73469  796.12245  816.51020  836.89796
[43]  857.28571  877.67347  898.06122  918.44898  938.83673  959.22449  979.61224
[50] 1000.00000

#via:
seq.int(from=1,to=1000,length.out=50)

Override to

 [1]   1   6  11  16  21  26  31  36  41  46  51  56  61  66  71  76  81  86  91  96 101
[22] 106 111 116 121 126 131 136 141 146 151 156 161 166 171 176 181 186 191 196 201 206
[43] 211 216 221 226 231 236 241 246

#via:
seq.int(from=1,by=5,length.out=50)

Override from

 [1]  755  760  765  770  775  780  785  790  795  800  805  810  815  820  825  830  835  840
[19]  845  850  855  860  865  870  875  880  885  890  895  900  905  910  915  920  925  930
[37]  935  940  945  950  955  960  965  970  975  980  985  990  995 1000

#via:
seq.int(to=1000,by=5,length.out=50)

A priori, R has no way of telling which of the above you'd like, nor should it. You as programmer need to decide which inputs take precedence.

And you're right that this should be documented; for now, take a look at the source of .Primitive("seq.int"), as linked originally by @nongkrong.

Upvotes: 5

Related Questions