-
Notifications
You must be signed in to change notification settings - Fork 135
Description
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