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

Indexing is a bit odd in the new tibble #760

Closed
mlane3 opened this issue Apr 14, 2020 · 4 comments
Closed

Indexing is a bit odd in the new tibble #760

mlane3 opened this issue Apr 14, 2020 · 4 comments
Milestone

Comments

@mlane3
Copy link

@mlane3 mlane3 commented Apr 14, 2020

Is the new invariants article set in stone or would be possible to make a documentation request?

library(tidyverse)
partition <- as.matrix(data.frame(Resample=c(1,2,3,4)))

# Create a data frame of y response and x1 predictor
# with intentionally unusually naming due to inherited data issue.

y.variable <- as.factor(c("false_318","false_318","false_318","true_130","true_130"))
x1 <- c(3225067,6907531,6911683,6991870,2222)

mydata <- tibble(y.variable=y.variable,x1=x1)
mydata[partition, ]
# Gives Error: `i` must have one dimension, not 2. 

This error will product the error "Error: i must have one dimension, not 2." However, by simply playing around a bit I figured out a work around.

partition2 <- as.vector(partition)
mydata[partition2,]

I am not strong it R, but for me it seemed a named vector [n,1] and ""matrix"" (really a vector) that is nx1 (n rows and 1 column) was the reason for the error. I researched more into this error and came across this page (https://github.com/tidyverse/tibble/blob/master/NEWS.md) and this:

Subset assignment ("subassignment") and also subsetting has become stricter. Symptoms:
**i must have one dimension, not 2**

The "invariants" article at https://tibble.tidyverse.org/dev/articles/invariants.html describes the invariants that the operations follow in tibble, and the most important differences to data frames. We tried to make subsetting and subassignment as safe as possible, so that errors are caught early on, while introducing as little friction as possible.

This made it clear that there are probably very good reasons that a named vector or a literal [nx1] area can no longer be passed into a list. However, I was hoping the documentation could include more examples so its a bit more clear to new users.

Thank you for your time,

mlane

@krlmlr krlmlr closed this as completed Apr 15, 2020
@krlmlr
Copy link
Member

@krlmlr krlmlr commented Apr 15, 2020

I don't see a problem description here.

@mlane3 mlane3 changed the title Cleaning up " Indexing is a bit odd in the new tibble Apr 16, 2020
@mlane3
Copy link
Author

@mlane3 mlane3 commented Apr 16, 2020

@krlmlr I am very sorry. My internet crashed around the time I tried to posting this, so I didn't think it posted. I have updated it.
(P.S. If it would be relevant to any tags, I would appreciate it. 👍 )

@krlmlr krlmlr reopened this Apr 17, 2020
@krlmlr krlmlr added this to the 3.0.1 milestone Apr 17, 2020
@krlmlr krlmlr closed this as completed in 9edb6b4 Apr 17, 2020
@krlmlr
Copy link
Member

@krlmlr krlmlr commented Apr 17, 2020

Thanks. Now:

library(tidyverse)
partition <- as.matrix(data.frame(Resample = c(1, 2, 3, 4)))

# Create a data frame of y response and x1 predictor
# with intentionally unusually naming due to inherited data issue.

y.variable <- as.factor(c("false_318", "false_318", "false_318", "true_130", "true_130"))
x1 <- c(3225067, 6907531, 6911683, 6991870, 2222)

mydata <- tibble(y.variable = y.variable, x1 = x1)
mydata[partition, ]
#> Warning: The `i` argument of ``[`()` can't be a matrix as of tibble 3.0.0.
#> Convert to a vector.
#> This warning is displayed once every 8 hours.
#> Call `lifecycle::last_warnings()` to see where this warning was generated.
#> # A tibble: 4 x 2
#>   y.variable      x1
#>   <fct>        <dbl>
#> 1 false_318  3225067
#> 2 false_318  6907531
#> 3 false_318  6911683
#> 4 true_130   6991870

Created on 2020-04-17 by the reprex package (v0.3.0)

krlmlr added a commit that referenced this issue Feb 25, 2021
tibble 3.0.1

- `[<-.tbl_df()` coerces matrices to data frames (#762).

- Use delayed import for cli to work around unload problems in downstream packages (#754).

- More soft-deprecation warnings are actually visible.

- If `.name_repair` is a function, no repair messages are shown (#763).

- Remove superseded signal for `as_tibble.list()`, because `as_tibble_row()` only works for size 1.

- `as_tibble(validate = )` now always triggers a deprecation warning.

- Subsetting and subassignment of rows with one-column matrices work again, with a deprecation warning (#760).

- Attempts to update a tibble row with an atomic vector give a clearer error message. Recycling message for subassignment appears only if target size is != 1.

- Tweak title of "Invariants" vignette.
@github-actions
Copy link

@github-actions github-actions bot commented Apr 18, 2021

This old thread has been automatically locked. If you think you have found something related to this, please open a new issue and link to this old issue if necessary.

@github-actions github-actions bot locked and limited conversation to collaborators Apr 18, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants