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

Fix corner case in new_data_frame(n = NULL) #894

Merged
merged 3 commits into from Mar 9, 2020

Conversation

krlmlr
Copy link
Member

@krlmlr krlmlr commented Mar 8, 2020

We should allow omitting n if row.names attribute is given.

Current behavior:

rlang::exec(
  vctrs::new_data_frame,
  list(),
  n = NULL, !!!attributes(data.frame(a = 1)[0])
)
#> Error: `n` and `row.names` must be consistent.

Created on 2020-03-08 by the reprex package (v0.3.0)

With this patch:

rlang::exec(
  vctrs::new_data_frame,
  list(),
  n = NULL, !!!attributes(data.frame(a = 1)[0])
)
#> data frame with 0 columns and 1 row

Created on 2020-03-08 by the reprex package (v0.3.0)

@@ -87,7 +87,9 @@ SEXP vctrs_new_data_frame(SEXP args) {
if (tag == R_RowNamesSymbol) {
// "row.names" is checked for consistency with n (if provided)
if (size != rownames_size(CAR(node))) {
Rf_errorcall(R_NilValue, "`n` and `row.names` must be consistent.");
if (n != R_NilValue) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you merge this if with the nesting if please.

@@ -281,9 +281,10 @@ test_that("attributes with special names are merged", {
"rowname"
)

expect_error(
# Can omit n if row.names attribute is given
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

n is not omitted in this test. Should probably be its own test_that() block.

@lionel- lionel- merged commit 0803c1b into r-lib:master Mar 9, 2020
@lionel-
Copy link
Member

lionel- commented Mar 9, 2020

Thanks!

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.

None yet

2 participants