Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the restrictions on seq.int?

Tags:

r

The seq man page states the following (emphasis mine):

Description

Generate regular sequences. seq is a standard generic with a default method. seq.int is a primitive which can be much faster but has a few restrictions.

The page doesn't actually describe what those restrictions are, though. Here's every other mention of seq.int there:

Arguments

[...]

length.out desired length of the sequence. A non-negative number, which for seq and seq.int will be rounded up if fractional.

[...]

Details

[...]

The interpretation of the unnamed arguments of seq and seq.int is not standard, and it is recommended always to name the arguments when programming.

[...]

seq.int is an internal generic which dispatches on methods for "seq" based on the class of the first supplied argument (before argument matching).

seq.int, seq_along and seq_len are primitive.

Value

seq.int and the default method of seq for numeric arguments return a vector of type "integer" or "double": programmers should not rely on which.

Other than stating that seq.int dispatches seq according to the class of its first argument, I don't see any "restrictions".

So, what are these restrictions?

like image 971
Wasabi Avatar asked Dec 17 '19 16:12

Wasabi


People also ask

What does seq int do in R?

seq() function in R Language is used to create a sequence of elements in a Vector. It takes the length and difference between values as optional argument.

What is seq INT?

seq.int is an internal generic which dispatches on methods for "seq" based on the class of the first supplied argument (before argument matching). Typical usages are seq(from, to) seq(from, to, by= ) seq(from, to, length.out= ) seq(along.with= ) seq(from) seq(length.out= )

How do you set a sequence in R?

The simplest way to create a sequence of numbers in R is by using the : operator. Type 1:20 to see how it works. That gave us every integer between (and including) 1 and 20 (an integer is a positive or negative counting number, including 0).

What is seq along in R?

The seq_along() in R is a built-in function that creates a vector that contains a sequence of numbers from 1 to the object's length. Thus, the seq_along() function creates a sequence the same length of the argument passed, and in the context of a for loop, is used to more easily create the index to iterate over.


1 Answers

seq is a standard generic function written in R. seq.int is a primitive function written in C. While both of them are written to do the same job, due do the quirks of their platforms, they can sometimes have certain restrictions. The following is an example.

enter image description here

Note that this is from an old version of R and is fixed in the current versions. These kinds of bugs have been observed throughout the development of R and they have been patched as soon as possible. The current versions of seq and seq.int now look almost identical. So, there should not be any more restrictions on seq.int.

like image 163
Santanu Avatar answered Oct 11 '22 06:10

Santanu