-
Notifications
You must be signed in to change notification settings - Fork 66
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
vec_slice() cannot slice 0-column data.frames properly #179
Comments
It seems rownames are lost here: Lines 108 to 109 in ed62f1e
|
To fix this, I feel we have to provide the expected length to library(vctrs)
x <- tibble::tibble(.rows = 3)
out <- lapply(x, vec_slice, 1)
# the expected length is 1, but neither of out nor x know it here
vec_restore(out, x)
#> # A tibble: 0 x 0 Created on 2019-02-07 by the reprex package (v0.2.1) Does this look OK...? if so, I'll make a PR. vec_restore <- function (x, to, ...) {
UseMethod("vec_restore", to)
}
vec_restore.data.frame <- function (x, to, n = NULL, ...) {
...
attr_to[["row.names"]] <- .set_row_names(n %||% df_length(x))
...
} |
I think if you have to supply arguments, it's a sign that you shouldn't be using |
Hmm..., thanks, I agree it's a bad sign. But, I don't think I "shouldn't be using Probably, we can add rownames again after |
The more I think about it, the more I think this use of I'm not sure what we should do here given that Alternatively, this might be resolved by #124, where we'll make |
Thanks, given the current |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
It turns out that the fixes needed for the newly focussed #199, also ended up fixing this issue. I think this is correct because I was just too aggressively throwing away the row names attribute (throwing the baby out with the bath water), but I'd appreciate it if you'd take a look at the patch and see if it makes sense to you too. |
@hadley Sorry, I don't think this is "fixed." The second one below no more raises an error, but the result seems still incorrect; the dimensions should be 3 x 0, and 3 x 1. library(vctrs)
library(tibble)
packageDescription("vctrs")["GithubSHA1"]
#> $GithubSHA1
#> [1] "3b80a81418d0f8037f86e875e80e5a73b2744485"
vec_slice(tibble(.rows = 3), 1:3)
#> # A tibble: 0 x 0
vec_slice(tibble(x = tibble(.rows = 3)), 1:3)
#> # A tibble: 0 x 1
#> # ... with 1 variable: x <lgl> Created on 2019-02-27 by the reprex package (v0.2.1) |
Ok, that's actually reassuring to me 😄 |
Ok, I am now pretty sure I have fixed it properly — it's sort of a hack on top of a hack, but if we're going to coerce into a list to avoid expensive |
Confirmed the fix, thanks! |
Created on 2019-01-31 by the reprex package (v0.2.1.9000)
The text was updated successfully, but these errors were encountered: