Skip to content

Conversation

@hcirellu
Copy link
Collaborator

@hcirellu hcirellu commented Jan 8, 2026

In addition to #202 I brought seq.integer64 closer to seq for integer.

The arguments from, to and by are coerced to integer64. If the coercion would result in an information loss, a warning is displayed. Since the coercion of length.out has no warning with integer, I didn't add it here.

seq(as.integer64(1L), 2.5)
# integer64
# [1] 1 2
# Warning message:
# In seq.integer64(as.integer64(1L), 2.5) :
#   argument 'to' is coerced to integer64

I also added some warnings that give a hint, that because of staying in integer64 the step width is truncated to integer64.

seq(as.integer64(10L), 20L, length.out=4L)
# integer64
# [1] 10 13 16 19
# Warning message:
# In seq.integer64(as.integer64(10L), 20L, length.out = 4L) :
#   the resulting 'by' is truncated to integer64

In addition, I added an error message, if the resulting sequence does not fit in integer64 anymore. Im my opinion this is better than getting a sequence with NA values.

seq(as.integer64(2^62), by=as.integer64(2^62), length.out=2L)
# Error in seq.integer64(as.integer64(2^62), by = as.integer64(2^62), length.out = 2L) : 
#   resulting sequence does not fit in integer64

I also fixed the missing dispatch of :.integer64 and made that also more consistent with R.

I also extended the tests for :.integer64 and seq.integer64.

Adresses (#211)

@hcirellu hcirellu marked this pull request as ready for review January 8, 2026 17:08
@MichaelChirico MichaelChirico added this to the 4.8.0 milestone Jan 8, 2026
@MichaelChirico
Copy link
Collaborator

Because it involves throwing a new warning where there was none before, I propose waiting until after the next release to consider this change.

@hcirellu
Copy link
Collaborator Author

Just have in mind, that with the actual main branch the following results differ from seq() in R.

seq(NA_integer64_)
# Error
seq(NA)
# [1] 1
seq(rep(NA_integer64_, 2))
# Error
seq(rep(NA, 2))
# [1] 1 2
seq.integer64()
# Error
seq()
# [1] 1
seq(as.integer64())
# Error
seq(as.integer64())
# integer(0)
seq(as.integer64(1:2))
# Error
seq(1:2)
# [1] 1 2
seq(as.integer64(1L), 10L, alon=NULL)
# integer64
# [1] 1 2 3 4 5 6 7 8 9 10
seq(1L, 10L, alon=NULL)
# integer(0)
seq(as.integer64(1L), 10L, by=NULL)
# integer64
# [1] 1 2 3 4 5 6 7 8 9 10
seq(1L, 10L, by=NULL)
# Error: 'by' must be of length 1
seq(as.integer64(1L), 10L, len=NULL)
# integer64
# [1] 1 2 3 4 5 6 7 8 9 10
seq(1L, 10L, len=NULL)
# Error: 'length.out' must be of length 1
seq(by=as.integer64(1:2))
# integer64
# [1] 1
seq(by=1:2)
# Error: 'by' must be of length 1
seq(len=as.integer64(1:2))
# Error
seq(len=1:2)
# 1
warning: first element used of 'length.out' argument

The following examples result in different error messages.

seq(NA_integer64_, 2L)
# Error: missing value where TRUE/FALSE needed
seq(NA, 2L)
# Error: 'from' must be a finite number
seq(to=NA_integer64_, 2L)
# Error: missing value where TRUE/FALSE needed
seq(to=NA, 2L)
# Error: 'to' must be a finite number
seq(len=NA_integer64_, 2L)
# Error: missing value where TRUE/FALSE needed
seq(len=NA, 2L)
# Error: 'length.out' must be a non-negative number
seq(as.integer64(1:2), 10L)
# Error: 'length = 2' in coercion to 'logical(1)'
seq(1:2, 10L)
# Error: 'from' must be of length 1
seq(to=as.integer64(1:2))
# Error: 'length = 2' in coercion to 'logical(1)'
seq(to=1:2)
# Error: 'to' must be of length 1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants