Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

first called on zero length input #309

Closed
jangorecki opened this issue Sep 13, 2019 · 1 comment
Closed

first called on zero length input #309

jangorecki opened this issue Sep 13, 2019 · 1 comment
Assignees
Labels
Milestone

Comments

@jangorecki
Copy link

We have just recently spotted this inconsistency (with relation to last function) in data.table. It was now amended. It looks to be the same in xts.

A = numeric()
xts::first(A)
#[1] NA
xts::last(A)
#numeric(0)

IMO it make sense to return numeric(0) from first(numeric()).
xts 0.11.2

@joshuaulrich
Copy link
Owner

Hi Jan, thanks for the report! I agree that both first() and last() should return numeric(0). That is consistent with head() and tail(). I will fix.

@joshuaulrich joshuaulrich self-assigned this Nov 19, 2019
@joshuaulrich joshuaulrich added this to the 0.12-0 milestone Nov 19, 2019
joshuaulrich added a commit that referenced this issue Nov 19, 2019
The default methods for first() and last() should return a zero-row
matrix if the input is a zero-length matrix. This makes them (almost)
consistent with head() and tail() in the utils package. (The only
difference is that utils::tail.matrix() adds rownames by default, and
last.default() will not.)

Also update the tests for vector inputs to check the output matches
the input, not the output of head()/tail(). This will avoid potential
test failures in the unlikely event that head()/tail() change in the
future.

See #309.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants