--- title: "Invariants: Comparing behavior with data frames" #output: rmarkdown::word_document output: rmarkdown::html_vignette vignette: > %\VignetteIndexEntry{Invariants: Comparing behavior with data frames} %\VignetteEngine{knitr::rmarkdown} %\VignetteEncoding{UTF-8} --- This vignette defines invariants for subsetting and subset-assignment for tibbles, and illustrates where their behaviour differs from data frames. The goal is to define a small set of invariants that consistently define how behaviors interact. Some behaviors are defined using functions of the vctrs package, e.g. `vec_slice()`, `vec_recycle()` and `vec_as_index()`. Refer to their documentation for more details about the invariants that they follow. The subsetting and subassignment operators for data frames and tibbles are particularly tricky, because they support both row and column indexes, both of which are optionally missing. We resolve this by first defining column access with `[[` and `$`, then column-wise subsetting with `[`, then row-wise subsetting, then the composition of both. ## Conventions In this article, all behaviors are demonstrated using one example data frame and its tibble equivalent: ```r library(tibble) library(vctrs) new_df <- function() { df <- data.frame(n = c(1L, NA, 3L, NA)) df$c <- letters[5:8] df$li <- list(9, 10:11, 12:14, "text") df } new_tbl <- function() { as_tibble(new_df()) } ``` Results of the same code for data frames and tibbles are presented side by side:
| ```r new_df() #> n c li #> 1 1 e 9 #> 2 NA f 10, 11 #> 3 3 g 12, 13, 14 #> 4 NA h text ``` |
```r
new_tbl()
#> # A tibble: 4 x 3
#> n c li
#>
|
| ```r new_df() #> n c li #> 1 1 e 9 #> 2 NA f 10, 11 #> 3 3 g 12, 13, 14 #> 4 NA h text ``` |
```r
new_tbl()
#> # A tibble: 4 x 3
#> n c li
#>
|
| ```r with_df(df$n <- rev(df$n), verbose = TRUE) #> { #> df <- new_df() #> df$n <- rev(df$n) #> df #> } #> n c li #> 1 NA e 9 #> 2 3 f 10, 11 #> 3 NA g 12, 13, 14 #> 4 1 h text ``` |
```r
with_tbl(tbl$n <- rev(tbl$n), verbose = TRUE)
#> {
#> tbl <- new_tbl()
#> tbl$n <- rev(tbl$n)
#> tbl
#> }
#> # A tibble: 4 x 3
#> n c li
#>
|
| ```r df[[1]] #> [1] 1 NA 3 NA ``` | ```r tbl[[1]] #> [1] 1 NA 3 NA ``` |
| ```r .subset2(df, 1) #> [1] 1 NA 3 NA ``` | ```r .subset2(tbl, 1) #> [1] 1 NA 3 NA ``` |
| ```r identical(df[[3]], .subset2(df, 3)) #> [1] TRUE ``` | ```r identical(tbl[[3]], .subset2(tbl, 3)) #> [1] TRUE ``` |
| ```r identical(df2[["df"]], .subset2(df2, "df")) #> [1] TRUE ``` | ```r identical(tbl2[["tbl"]], .subset2(tbl2, "tbl")) #> [1] TRUE ``` |
| ```r vec_size(df[[1]]) #> [1] 4 ``` | ```r vec_size(tbl[[1]]) #> [1] 4 ``` |
| ```r vec_size(df[[3]]) #> [1] 4 ``` | ```r vec_size(tbl[[3]]) #> [1] 4 ``` |
| ```r vec_size(df2[[1]]) #> [1] 4 ``` | ```r vec_size(tbl2[[1]]) #> [1] 4 ``` |
| ```r vec_size(df2[[2]]) #> [1] 4 ``` | ```r vec_size(tbl2[[2]]) #> [1] 4 ``` |
| ```r df[[1:2]] #> [1] NA ``` |
```r
tbl[[1:2]]
```
```
#> Warning: The `j` argument of `[[.tbl_df`
#> can't be a vector of length 2 as of
#> tibble 3.0.0.
#> Recursive subsetting is deprecated for
#> tibbles.
```
```
#> [1] NA
```
|
|
```r
df[[c("n", "c")]]
```
```
#> Error in .subset2(x, i, exact = exact):
#> subscript out of bounds
```
|
```r
tbl[[c("n", "c")]]
```
```
#> Error in `vectbl_as_col_location2()`:
#> ! Must extract column with a single
#> valid subscript.
#> x Subscript `c("n", "c")` has size 2 but
#> must be size 1.
```
|
| ```r df[[TRUE]] #> [1] 1 NA 3 NA ``` |
```r
tbl[[TRUE]]
```
```
#> Error in `vectbl_as_col_location2()`:
#> ! Must extract column with a single
#> valid subscript.
#> x Subscript `TRUE` has the wrong type
#> `logical`.
#> i It must be numeric or character.
```
|
|
```r
df[[mean]]
```
```
#> Error in .subset2(x, i, exact = exact):
#> invalid subscript type 'closure'
```
|
```r
tbl[[mean]]
```
```
#> Error in `vectbl_as_col_location2()`:
#> ! Must extract column with a single
#> valid subscript.
#> x Subscript `mean` has the wrong type
#> `function`.
#> i It must be numeric or character.
```
|
| ```r df[[NA]] #> NULL ``` |
```r
tbl[[NA]]
```
```
#> Error in `vectbl_as_col_location2()`:
#> ! Must extract column with a single
#> valid subscript.
#> x Subscript `NA` can't be `NA`.
```
|
| ```r df[[NA_character_]] #> NULL ``` |
```r
tbl[[NA_character_]]
```
```
#> Error in `vectbl_as_col_location2()`:
#> ! Must extract column with a single
#> valid subscript.
#> x Subscript `NA_character_` can't be
#> `NA`.
```
|
| ```r df[[NA_integer_]] #> NULL ``` |
```r
tbl[[NA_integer_]]
```
```
#> Error in `vectbl_as_col_location2()`:
#> ! Must extract column with a single
#> valid subscript.
#> x Subscript `NA_integer_` can't be `NA`.
```
|
|
```r
df[[-1]]
```
```
#> Error in .subset2(x, i, exact = exact):
#> invalid negative subscript in get1index
#> |
```r
tbl[[-1]]
```
```
#> Error in `vectbl_as_col_location2()`:
#> ! Must extract column with a single
#> valid subscript.
#> x Subscript `-1` has value -1 but must
#> be a positive location.
```
|
|
```r
df[[4]]
```
```
#> Error in .subset2(x, i, exact = exact):
#> subscript out of bounds
```
|
```r
tbl[[4]]
```
```
#> Error in `vec_as_location2_result()`:
#> ! Can't subset columns past the end.
#> i Location 4 doesn't exist.
#> i There are only 3 columns.
```
|
| ```r df[[1.5]] #> [1] 1 NA 3 NA ``` |
```r
tbl[[1.5]]
```
```
#> Error in `vectbl_as_col_location2()`:
#> ! Must extract column with a single
#> valid subscript.
#> x Subscript `1.5` has the wrong type
#> `double`.
#> i It must be numeric or character.
```
|
| ```r df[[Inf]] #> NULL ``` |
```r
tbl[[Inf]]
```
```
#> Error in `vectbl_as_col_location2()`:
#> ! Must extract column with a single
#> valid subscript.
#> x Subscript `Inf` has the wrong type
#> `double`.
#> i It must be numeric or character.
```
|
| ```r df[["x"]] #> NULL ``` | ```r tbl[["x"]] #> NULL ``` |
| ```r df$n #> [1] 1 NA 3 NA ``` | ```r tbl$n #> [1] 1 NA 3 NA ``` |
| ```r df$"n" #> [1] 1 NA 3 NA ``` | ```r tbl$"n" #> [1] 1 NA 3 NA ``` |
| ```r df[["n"]] #> [1] 1 NA 3 NA ``` | ```r tbl[["n"]] #> [1] 1 NA 3 NA ``` |
| ```r identical(df$li, df[["li"]]) #> [1] TRUE ``` | ```r identical(tbl$li, tbl[["li"]]) #> [1] TRUE ``` |
| ```r identical(df2$tb, df2[["tb"]]) #> [1] TRUE ``` | ```r identical(tbl2$tb, tbl2[["tb"]]) #> [1] TRUE ``` |
| ```r identical(df2$m, df2[["m"]]) #> [1] TRUE ``` | ```r identical(tbl2$m, tbl2[["m"]]) #> [1] TRUE ``` |
| ```r df$l #> [[1]] #> [1] 9 #> #> [[2]] #> [1] 10 11 #> #> [[3]] #> [1] 12 13 14 #> #> [[4]] #> [1] "text" ``` |
```r
tbl$l
```
```
#> Warning: Unknown or uninitialised
#> column: `l`.
```
```
#> NULL
```
|
| ```r df$not_present #> NULL ``` |
```r
tbl$not_present
```
```
#> Warning: Unknown or uninitialised
#> column: `not_present`.
```
```
#> NULL
```
|
| ```r df[1:2] #> n c #> 1 1 e #> 2 NA f #> 3 3 g #> 4 NA h ``` |
```r
tbl[1:2]
#> # A tibble: 4 x 2
#> n c
#> |
| ```r df[c(1, 1)] #> n n.1 #> 1 1 1 #> 2 NA NA #> 3 3 3 #> 4 NA NA ``` |
```r
tbl[c(1, 1)]
#> # A tibble: 4 x 2
#> n n
#> |
| ```r df[integer()] #> data frame with 0 columns and 4 rows ``` | ```r tbl[integer()] #> # A tibble: 4 x 0 ``` |
| ```r df[is.na(df)] #> [[1]] #> [1] NA #> #> [[2]] #> [1] NA ``` | ```r tbl[is.na(tbl)] #> [1] NA NA ``` |
| ```r df[!is.na(df)] #> [[1]] #> [1] 1 #> #> [[2]] #> [1] 3 #> #> [[3]] #> [1] "e" #> #> [[4]] #> [1] "f" #> #> [[5]] #> [1] "g" #> #> [[6]] #> [1] "h" #> #> [[7]] #> [1] 9 #> #> [[8]] #> [1] 10 11 #> #> [[9]] #> [1] 12 13 14 #> #> [[10]] #> [1] "text" ``` |
```r
tbl[!is.na(tbl)]
```
```
#> Error:
#> ! Can't combine `n`
|
| ```r df[, 1] #> [1] 1 NA 3 NA ``` |
```r
tbl[, 1]
#> # A tibble: 4 x 1
#> n
#> |
| ```r df[, 1:2] #> n c #> 1 1 e #> 2 NA f #> 3 3 g #> 4 NA h ``` |
```r
tbl[, 1:2]
#> # A tibble: 4 x 2
#> n c
#> |
| ```r identical(df[, 2:3], df[2:3]) #> [1] TRUE ``` | ```r identical(tbl[, 2:3], tbl[2:3]) #> [1] TRUE ``` |
| ```r identical(df2[, 1:2], df2[1:2]) #> [1] TRUE ``` | ```r identical(tbl2[, 1:2], tbl2[1:2]) #> [1] TRUE ``` |
| ```r df[, 1, drop = TRUE] #> [1] 1 NA 3 NA ``` | ```r tbl[, 1, drop = TRUE] #> [1] 1 NA 3 NA ``` |
| ```r identical(df[, 3, drop = TRUE], df[[3]]) #> [1] TRUE ``` | ```r identical(tbl[, 3, drop = TRUE], tbl[[3]]) #> [1] TRUE ``` |
| ```r identical(df2[, 1, drop = TRUE], df2[[1]]) #> [1] TRUE ``` | ```r identical(tbl2[, 1, drop = TRUE], tbl2[[1]]) #> [1] TRUE ``` |
| ```r identical(df2[, 2, drop = TRUE], df2[[2]]) #> [1] TRUE ``` | ```r identical(tbl2[, 2, drop = TRUE], tbl2[[2]]) #> [1] TRUE ``` |
| ```r df[3, ] #> n c li #> 3 3 g 12, 13, 14 ``` |
```r
tbl[3, ]
#> # A tibble: 1 x 3
#> n c li
#>
|
|
```r
df[mean, ]
```
```
#> Error in xj[i]: invalid subscript type
#> 'closure'
```
|
```r
tbl[mean, ]
```
```
#> Error in `vectbl_as_row_location()`:
#> ! Must subset rows with a valid
#> subscript vector.
#> x Subscript `mean` has the wrong type
#> `function`.
#> i It must be logical, numeric, or
#> character.
```
|
|
```r
df[list(1), ]
```
```
#> Error in xj[i]: invalid subscript type
#> 'list'
```
|
```r
tbl[list(1), ]
```
```
#> Error in `vectbl_as_row_location()`:
#> ! Must subset rows with a valid
#> subscript vector.
#> x Subscript `list(1)` has the wrong type
#> `list`.
#> i It must be logical, numeric, or
#> character.
```
|
| ```r df["1", ] #> n c li #> 1 1 e 9 ``` |
```r
tbl["1", ]
#> # A tibble: 1 x 3
#> n c li
#>
|
|
```r
df[10, ]
#> n c li
#> NA NA |
```r
tbl[10, ]
```
```
#> Warning: The `i` argument of `[.tbl_df`
#> must lie in [0, rows] if positive, as of
#> tibble 3.0.0.
#> Use `NA_integer_` as row index to obtain
#> a row full of `NA` values.
```
```
#> # A tibble: 1 x 3
#> n c li
#>
|
|
```r
df["x", ]
#> n c li
#> NA NA |
```r
tbl["x", ]
```
```
#> Warning: The `i` argument of `[.tbl_df`
#> must use valid row names as of tibble
#> 3.0.0.
#> Use `NA_integer_` as row index to obtain
#> a row full of `NA` values.
```
```
#> # A tibble: 1 x 3
#> n c li
#>
|
| ```r df[c(TRUE, FALSE), ] #> n c li #> 1 1 e 9 #> 3 3 g 12, 13, 14 ``` |
```r
tbl[c(TRUE, FALSE), ]
```
```
#> Error in `vectbl_as_row_location()`:
#> ! Must subset rows with a valid
#> subscript vector.
#> i Logical subscripts must match the size
#> of the indexed input.
#> x Input has size 4 but subscript
#> `c(TRUE, FALSE)` has size 2.
```
|
|
```r
df[NA, ]
#> n c li
#> NA NA |
```r
tbl[NA, ]
#> # A tibble: 4 x 3
#> n c li
#>
|
|
```r
df[NA_integer_, ]
#> n c li
#> NA NA |
```r
tbl[NA_integer_, ]
#> # A tibble: 1 x 3
#> n c li
#>
|
| ```r df[1, , drop = TRUE] #> $n #> [1] 1 #> #> $c #> [1] "e" #> #> $li #> $li[[1]] #> [1] 9 ``` |
```r
tbl[1, , drop = TRUE]
#> # A tibble: 1 x 3
#> n c li
#>
|
| ```r df[1, 1] #> [1] 1 ``` |
```r
tbl[1, 1]
#> # A tibble: 1 x 1
#> n
#> |
| ```r df[1, ][1] #> n #> 1 1 ``` |
```r
tbl[1, ][1]
#> # A tibble: 1 x 1
#> n
#> |
| ```r identical(df[1, 2:3], df[2:3][1, ]) #> [1] TRUE ``` | ```r identical(tbl[1, 2:3], tbl[2:3][1, ]) #> [1] TRUE ``` |
| ```r identical(df[2:3, 1], df[1][2:3, ]) #> [1] TRUE ``` | ```r identical(tbl[2:3, 1], tbl[1][2:3, ]) #> [1] TRUE ``` |
| ```r identical(df2[2:3, 1:2], df2[1:2][2:3, ]) #> [1] TRUE ``` | ```r identical(tbl2[2:3, 1:2], tbl2[1:2][2:3, ]) #> [1] TRUE ``` |
| ```r with_df(df[[1]] <- 0) #> n c li #> 1 0 e 9 #> 2 0 f 10, 11 #> 3 0 g 12, 13, 14 #> 4 0 h text ``` |
```r
with_tbl(tbl[[1]] <- 0)
#> # A tibble: 4 x 3
#> n c li
#>
|
| ```r with_df(df[[3]] <- 4:1) #> n c li #> 1 1 e 4 #> 2 NA f 3 #> 3 3 g 2 #> 4 NA h 1 ``` |
```r
with_tbl(tbl[[3]] <- 4:1)
#> # A tibble: 4 x 3
#> n c li
#> |
| ```r with_df2(df2[[1]] <- 0) #> tb m.1 m.2 m.3 m.4 #> 1 0 1 0 0 0 #> 2 0 0 1 0 0 #> 3 0 0 0 1 0 #> 4 0 0 0 0 1 ``` |
```r
with_tbl2(tbl2[[1]] <- 0)
#> # A tibble: 4 x 2
#> tb m[,1] [,2] [,3] [,4]
#> |
| ```r with_df2(df2[[2]] <- 4:1) #> tb.n tb.c tb.li m #> 1 1 e 9 4 #> 2 NA f 10, 11 3 #> 3 3 g 12, 13, 14 2 #> 4 NA h text 1 ``` |
```r
with_tbl2(tbl2[[2]] <- 4:1)
#> # A tibble: 4 x 2
#> tb$n $c $li m
#> |
| ```r with_df(df[[1]] <- 0) #> n c li #> 1 0 e 9 #> 2 0 f 10, 11 #> 3 0 g 12, 13, 14 #> 4 0 h text ``` |
```r
with_tbl(tbl[[1]] <- 0)
#> # A tibble: 4 x 3
#> n c li
#>
|
| ```r with_df(df[["c"]] <- 0) #> n c li #> 1 1 0 9 #> 2 NA 0 10, 11 #> 3 3 0 12, 13, 14 #> 4 NA 0 text ``` |
```r
with_tbl(tbl[["c"]] <- 0)
#> # A tibble: 4 x 3
#> n c li
#>
|
| ```r with_df(df[[TRUE]] <- 0) #> n c li #> 1 0 e 9 #> 2 0 f 10, 11 #> 3 0 g 12, 13, 14 #> 4 0 h text ``` |
```r
with_tbl(tbl[[TRUE]] <- 0)
```
```
#> Error in `vectbl_as_col_location2()`:
#> ! Must assign to column with a single
#> valid subscript.
#> x Subscript `TRUE` has the wrong type
#> `logical`.
#> i It must be numeric or character.
```
|
|
```r
with_df(df[[1:3]] <- 0)
```
```
#> Error in `[[<-`(`*tmp*`, i, value =
#> value): recursive indexing failed at
#> level 2
```
|
```r
with_tbl(tbl[[1:3]] <- 0)
```
```
#> Error in `vectbl_as_col_location2()`:
#> ! Must assign to column with a single
#> valid subscript.
#> x Subscript `1:3` has size 3 but must be
#> size 1.
```
|
|
```r
with_df(df[[c("n", "c")]] <- 0)
```
```
#> Error in x[[i]] <- value: more elements
#> supplied than there are to replace
```
|
```r
with_tbl(tbl[[c("n", "c")]] <- 0)
```
```
#> Error in `vectbl_as_col_location2()`:
#> ! Must assign to column with a single
#> valid subscript.
#> x Subscript `c("n", "c")` has size 2 but
#> must be size 1.
```
|
|
```r
with_df(df[[FALSE]] <- 0)
```
```
#> Error in x[[i]] <- value: attempt to
#> select less than one element in
#> integerOneIndex
```
|
```r
with_tbl(tbl[[FALSE]] <- 0)
```
```
#> Error in `vectbl_as_col_location2()`:
#> ! Must assign to column with a single
#> valid subscript.
#> x Subscript `FALSE` has the wrong type
#> `logical`.
#> i It must be numeric or character.
```
|
|
```r
with_df(df[[1:2]] <- 0)
```
```
#> Error in x[[i]] <- value: more elements
#> supplied than there are to replace
```
|
```r
with_tbl(tbl[[1:2]] <- 0)
```
```
#> Error in `vectbl_as_col_location2()`:
#> ! Must assign to column with a single
#> valid subscript.
#> x Subscript `1:2` has size 2 but must be
#> size 1.
```
|
|
```r
with_df(df[[NA_integer_]] <- 0)
```
```
#> Error in x[[i]] <- value: attempt to
#> select more than one element in
#> integerOneIndex
```
|
```r
with_tbl(tbl[[NA_integer_]] <- 0)
```
```
#> Error in `vectbl_as_col_location2()`:
#> ! Must assign to column with a single
#> valid subscript.
#> x Subscript `NA_integer_` can't be `NA`.
```
|
|
```r
with_df(df[[NA]] <- 0)
```
```
#> Error in x[[i]] <- value: attempt to
#> select more than one element in
#> integerOneIndex
```
|
```r
with_tbl(tbl[[NA]] <- 0)
```
```
#> Error in `vectbl_as_col_location2()`:
#> ! Must assign to column with a single
#> valid subscript.
#> x Subscript `NA` can't be `NA`.
```
|
|
```r
with_df(df[[NA_character_]] <- 0)
```
```
#> Error in if (names(x)[nc] == "")
#> names(x)[nc] <- paste0("V", nc): missing
#> value where TRUE/FALSE needed
```
|
```r
with_tbl(tbl[[NA_character_]] <- 0)
```
```
#> Error in `vectbl_as_col_location2()`:
#> ! Must assign to column with a single
#> valid subscript.
#> x Subscript `NA_character_` can't be
#> `NA`.
```
|
| ```r with_df(df[["li"]] <- list(0)) #> n c li #> 1 1 e 0 #> 2 NA f 0 #> 3 3 g 0 #> 4 NA h 0 ``` |
```r
with_tbl(tbl[["li"]] <- list(0))
#> # A tibble: 4 x 3
#> n c li
#>
|
|
```r
with_df2(df2[["tb"]] <- df[1, ])
```
```
#> Error in `[[<-.data.frame`(`*tmp*`,
#> "tb", value = structure(list(n = 1L, :
#> replacement has 1 row, data has 4
```
|
```r
with_tbl2(tbl2[["tb"]] <- tbl[1, ])
#> # A tibble: 4 x 2
#> tb$n $c $li m[,1] [,2]
#> |
|
```r
with_df2(df2[["m"]] <- df2[["m"]][1, , drop = FALSE])
```
```
#> Error in `[[<-.data.frame`(`*tmp*`, "m",
#> value = structure(c(1, 0, 0, :
#> replacement has 1 row, data has 4
```
|
```r
with_tbl2(tbl2[["m"]] <- tbl2[["m"]][1, , drop = FALSE])
#> # A tibble: 4 x 2
#> tb$n $c $li m[,1] [,2]
#> |
| ```r with_df(df[[1]] <- 1) #> n c li #> 1 1 e 9 #> 2 1 f 10, 11 #> 3 1 g 12, 13, 14 #> 4 1 h text ``` |
```r
with_tbl(tbl[[1]] <- 1)
#> # A tibble: 4 x 3
#> n c li
#>
|
| ```r with_df(df[[1]] <- 4:1) #> n c li #> 1 4 e 9 #> 2 3 f 10, 11 #> 3 2 g 12, 13, 14 #> 4 1 h text ``` |
```r
with_tbl(tbl[[1]] <- 4:1)
#> # A tibble: 4 x 3
#> n c li
#>
|
|
```r
with_df(df[[1]] <- 3:1)
```
```
#> Error in `[[<-.data.frame`(`*tmp*`, 1,
#> value = 3:1): replacement has 3 rows,
#> data has 4
```
|
```r
with_tbl(tbl[[1]] <- 3:1)
```
```
#> Error:
#> ! Assigned data `3:1` must be compatible
#> with existing data.
#> x Existing data has 4 rows.
#> x Assigned data has 3 rows.
#> i Only vectors of size 1 are recycled.
```
|
| ```r with_df(df[[1]] <- 2:1) #> n c li #> 1 2 e 9 #> 2 1 f 10, 11 #> 3 2 g 12, 13, 14 #> 4 1 h text ``` |
```r
with_tbl(tbl[[1]] <- 2:1)
```
```
#> Error:
#> ! Assigned data `2:1` must be compatible
#> with existing data.
#> x Existing data has 4 rows.
#> x Assigned data has 2 rows.
#> i Only vectors of size 1 are recycled.
```
|
| ```r with_df(df[["x"]] <- 0) #> n c li x #> 1 1 e 9 0 #> 2 NA f 10, 11 0 #> 3 3 g 12, 13, 14 0 #> 4 NA h text 0 ``` |
```r
with_tbl(tbl[["x"]] <- 0)
#> # A tibble: 4 x 4
#> n c li x
#> |
| ```r with_df(df[[4]] <- 0) #> n c li V4 #> 1 1 e 9 0 #> 2 NA f 10, 11 0 #> 3 3 g 12, 13, 14 0 #> 4 NA h text 0 ``` |
```r
with_tbl(tbl[[4]] <- 0)
#> # A tibble: 4 x 4
#> n c li ...4
#> |
|
```r
with_df(df[[5]] <- 0)
```
```
#> Warning in format.data.frame(if (omit)
#> x[seq_len(n0), , drop = FALSE] else
#> x, : corrupt data frame: columns will be
#> truncated or padded with NAs
```
```
#> n c li V5
#> 1 1 e 9 NULL 0
#> 2 NA f 10, 11 |
```r
with_tbl(tbl[[5]] <- 0)
```
```
#> Error in
#> `numtbl_as_col_location_assign()`:
#> ! Can't assign to columns beyond the end
#> with non-consecutive locations.
#> i Input has size 3.
#> x Subscript `5` contains non-consecutive
#> location 5.
```
|
| ```r with_df(df[[1]] <- df[[2]]) #> n c li #> 1 e e 9 #> 2 f f 10, 11 #> 3 g g 12, 13, 14 #> 4 h h text ``` |
```r
with_tbl(tbl[[1]] <- tbl[[2]])
#> # A tibble: 4 x 3
#> n c li
#>
|
| ```r with_df(df[[2]] <- df[[3]]) #> n c li #> 1 1 9 9 #> 2 NA 10, 11 10, 11 #> 3 3 12, 13, 14 12, 13, 14 #> 4 NA text text ``` |
```r
with_tbl(tbl[[2]] <- tbl[[3]])
#> # A tibble: 4 x 3
#> n c li
#>
|
| ```r with_df(df[[3]] <- df2[[1]]) #> n c li.n li.c li.li #> 1 1 e 1 e 9 #> 2 NA f NA f 10, 11 #> 3 3 g 3 g 12, 13, 14 #> 4 NA h NA h text ``` |
```r
with_tbl(tbl[[3]] <- tbl2[[1]])
#> # A tibble: 4 x 3
#> n c li$n $c $li
#>
|
| ```r with_df2(df2[[1]] <- df2[[2]]) #> tb.1 tb.2 tb.3 tb.4 m.1 m.2 m.3 m.4 #> 1 1 0 0 0 1 0 0 0 #> 2 0 1 0 0 0 1 0 0 #> 3 0 0 1 0 0 0 1 0 #> 4 0 0 0 1 0 0 0 1 ``` |
```r
with_tbl2(tbl2[[1]] <- tbl2[[2]])
#> # A tibble: 4 x 2
#> tb[,1] [,2] [,3] [,4] m[,1] [,2]
#> |
| ```r with_df2(df2[[2]] <- df[[1]]) #> tb.n tb.c tb.li m #> 1 1 e 9 1 #> 2 NA f 10, 11 NA #> 3 3 g 12, 13, 14 3 #> 4 NA h text NA ``` |
```r
with_tbl2(tbl2[[2]] <- tbl[[1]])
#> # A tibble: 4 x 2
#> tb$n $c $li m
#> |
| ```r with_df(df[[1]] <- NULL) #> c li #> 1 e 9 #> 2 f 10, 11 #> 3 g 12, 13, 14 #> 4 h text ``` |
```r
with_tbl(tbl[[1]] <- NULL)
#> # A tibble: 4 x 2
#> c li
#>
|
| ```r with_df2(df2[[2]] <- NULL) #> tb.n tb.c tb.li #> 1 1 e 9 #> 2 NA f 10, 11 #> 3 3 g 12, 13, 14 #> 4 NA h text ``` |
```r
with_tbl2(tbl2[[2]] <- NULL)
#> # A tibble: 4 x 1
#> tb$n $c $li
#>
|
| ```r with_df(df[["q"]] <- NULL) #> n c li #> 1 1 e 9 #> 2 NA f 10, 11 #> 3 3 g 12, 13, 14 #> 4 NA h text ``` |
```r
with_tbl(tbl[["q"]] <- NULL)
#> # A tibble: 4 x 3
#> n c li
#>
|
| ```r with_df(df$n <- 0) #> n c li #> 1 0 e 9 #> 2 0 f 10, 11 #> 3 0 g 12, 13, 14 #> 4 0 h text ``` |
```r
with_tbl(tbl$n <- 0)
#> # A tibble: 4 x 3
#> n c li
#>
|
| ```r with_df(df[["n"]] <- 0) #> n c li #> 1 0 e 9 #> 2 0 f 10, 11 #> 3 0 g 12, 13, 14 #> 4 0 h text ``` |
```r
with_tbl(tbl[["n"]] <- 0)
#> # A tibble: 4 x 3
#> n c li
#>
|
| ```r with_df(df$"n" <- 0) #> n c li #> 1 0 e 9 #> 2 0 f 10, 11 #> 3 0 g 12, 13, 14 #> 4 0 h text ``` |
```r
with_tbl(tbl$"n" <- 0)
#> # A tibble: 4 x 3
#> n c li
#>
|
| ```r with_df(df$l <- 0) #> n c li l #> 1 1 e 9 0 #> 2 NA f 10, 11 0 #> 3 3 g 12, 13, 14 0 #> 4 NA h text 0 ``` |
```r
with_tbl(tbl$l <- 0)
#> # A tibble: 4 x 4
#> n c li l
#> |
| ```r with_df(df[["l"]] <- 0) #> n c li l #> 1 1 e 9 0 #> 2 NA f 10, 11 0 #> 3 3 g 12, 13, 14 0 #> 4 NA h text 0 ``` |
```r
with_tbl(tbl[["l"]] <- 0)
#> # A tibble: 4 x 4
#> n c li l
#> |
| ```r with_df(df[1:2] <- list("x", 4:1)) #> n c li #> 1 x 4 9 #> 2 x 3 10, 11 #> 3 x 2 12, 13, 14 #> 4 x 1 text ``` |
```r
with_tbl(tbl[1:2] <- list("x", 4:1))
#> # A tibble: 4 x 3
#> n c li
#>
|
| ```r with_df(df[c("li", "x", "c")] <- list("x", 4:1, NULL)) #> n li x #> 1 1 x 4 #> 2 NA x 3 #> 3 3 x 2 #> 4 NA x 1 ``` |
```r
with_tbl(tbl[c("li", "x", "c")] <- list("x", 4:1, NULL))
#> # A tibble: 4 x 3
#> n li x
#> |
| ```r with_df(df[1:2] <- list(1)) #> n c li #> 1 1 1 9 #> 2 1 1 10, 11 #> 3 1 1 12, 13, 14 #> 4 1 1 text ``` |
```r
with_tbl(tbl[1:2] <- list(1))
#> # A tibble: 4 x 3
#> n c li
#>
|
|
```r
with_df(df[1:2] <- list(0, 0, 0))
```
```
#> Warning in `[<-.data.frame`(`*tmp*`,
#> 1:2, value = list(0, 0, 0)): provided 3
#> variables to replace 2 variables
```
```
#> n c li
#> 1 0 0 9
#> 2 0 0 10, 11
#> 3 0 0 12, 13, 14
#> 4 0 0 text
```
|
```r
with_tbl(tbl[1:2] <- list(0, 0, 0))
```
```
#> Error in `vectbl_as_new_col_index()`:
#> ! Can't recycle `list(0, 0, 0)` (size 3)
#> to size 2.
```
|
| ```r with_df(df[1:3] <- list(0, 0)) #> n c li #> 1 0 0 0 #> 2 0 0 0 #> 3 0 0 0 #> 4 0 0 0 ``` |
```r
with_tbl(tbl[1:3] <- list(0, 0))
```
```
#> Error in `vectbl_as_new_col_index()`:
#> ! Can't recycle `list(0, 0)` (size 2) to
#> size 3.
```
|
|
```r
with_df(df[c(1, 1)] <- list(1, 2))
```
```
#> Error in `[<-.data.frame`(`*tmp*`, c(1,
#> 1), value = list(1, 2)): duplicate
#> subscripts for columns
```
|
```r
with_tbl(tbl[c(1, 1)] <- list(1, 2))
```
```
#> Error:
#> ! Column index 1 is used more than once
#> for assignment.
```
|
| ```r with_df(df[1:2] <- list(NULL, 4:1)) #> c li #> 1 4 9 #> 2 3 10, 11 #> 3 2 12, 13, 14 #> 4 1 text ``` |
```r
with_tbl(tbl[1:2] <- list(NULL, 4:1))
#> # A tibble: 4 x 2
#> c li
#>
|
|
```r
with_df(df[NA] <- list("x"))
```
```
#> Error in `[<-.data.frame`(`*tmp*`, NA,
#> value = list("x")): missing values are
#> not allowed in subscripted assignments
#> of data frames
```
|
```r
with_tbl(tbl[NA] <- list("x"))
```
```
#> Error:
#> ! Can't use NA as column index with `[`
#> at positions 1, 2, and 3.
```
|
|
```r
with_df(df[NA_integer_] <- list("x"))
```
```
#> Error in `[<-.data.frame`(`*tmp*`,
#> NA_integer_, value = list("x")): missing
#> values are not allowed in subscripted
#> assignments of data frames
```
|
```r
with_tbl(tbl[NA_integer_] <- list("x"))
```
```
#> Error:
#> ! Can't use NA as column index in a
#> tibble for assignment.
```
|
|
```r
with_df(df[NA_character_] <- list("x"))
```
```
#> Error in `[<-.data.frame`(`*tmp*`,
#> NA_character_, value = list("x")):
#> missing values are not allowed in
#> subscripted assignments of data frames
```
|
```r
with_tbl(tbl[NA_character_] <- list("x"))
```
```
#> Error:
#> ! Can't use NA as column index in a
#> tibble for assignment.
```
|
| ```r with_df(df[1] <- df[2]) #> n c li #> 1 e e 9 #> 2 f f 10, 11 #> 3 g g 12, 13, 14 #> 4 h h text ``` |
```r
with_tbl(tbl[1] <- tbl[2])
#> # A tibble: 4 x 3
#> n c li
#>
|
| ```r with_df(df[2] <- df[3]) #> n c li #> 1 1 9 9 #> 2 NA 10, 11 10, 11 #> 3 3 12, 13, 14 12, 13, 14 #> 4 NA text text ``` |
```r
with_tbl(tbl[2] <- tbl[3])
#> # A tibble: 4 x 3
#> n c li
#>
|
| ```r with_df(df[3] <- df2[1]) #> n c li.n li.c li.li #> 1 1 e 1 e 9 #> 2 NA f NA f 10, 11 #> 3 3 g 3 g 12, 13, 14 #> 4 NA h NA h text ``` |
```r
with_tbl(tbl[3] <- tbl2[1])
#> # A tibble: 4 x 3
#> n c li$n $c $li
#>
|
| ```r with_df2(df2[1] <- df2[2]) #> tb.1 tb.2 tb.3 tb.4 m.1 m.2 m.3 m.4 #> 1 1 0 0 0 1 0 0 0 #> 2 0 1 0 0 0 1 0 0 #> 3 0 0 1 0 0 0 1 0 #> 4 0 0 0 1 0 0 0 1 ``` |
```r
with_tbl2(tbl2[1] <- tbl2[2])
#> # A tibble: 4 x 2
#> tb[,1] [,2] [,3] [,4] m[,1] [,2]
#> |
| ```r with_df2(df2[2] <- df[1]) #> tb.n tb.c tb.li m #> 1 1 e 9 1 #> 2 NA f 10, 11 NA #> 3 3 g 12, 13, 14 3 #> 4 NA h text NA ``` |
```r
with_tbl2(tbl2[2] <- tbl[1])
#> # A tibble: 4 x 2
#> tb$n $c $li m
#> |
| ```r with_df(df[c("x", "y")] <- tibble("x", x = 4:1)) #> n c li x y #> 1 1 e 9 x 4 #> 2 NA f 10, 11 x 3 #> 3 3 g 12, 13, 14 x 2 #> 4 NA h text x 1 ``` |
```r
with_tbl(tbl[c("x", "y")] <- tibble("x", x = 4:1))
#> # A tibble: 4 x 5
#> n c li x y
#> |
| ```r with_df(df[3:4] <- list("x", x = 4:1)) #> n c li x #> 1 1 e x 4 #> 2 NA f x 3 #> 3 3 g x 2 #> 4 NA h x 1 ``` |
```r
with_tbl(tbl[3:4] <- list("x", x = 4:1))
#> # A tibble: 4 x 4
#> n c li x
#> |
| ```r with_df(df[4] <- list(4:1)) #> n c li V4 #> 1 1 e 9 4 #> 2 NA f 10, 11 3 #> 3 3 g 12, 13, 14 2 #> 4 NA h text 1 ``` |
```r
with_tbl(tbl[4] <- list(4:1))
#> # A tibble: 4 x 4
#> n c li ...4
#> |
|
```r
with_df(df[5] <- list(4:1))
```
```
#> Error in `[<-.data.frame`(`*tmp*`, 5,
#> value = list(4:1)): new columns would
#> leave holes after existing columns
```
|
```r
with_tbl(tbl[5] <- list(4:1))
```
```
#> Error in
#> `numtbl_as_col_location_assign()`:
#> ! Can't assign to columns beyond the end
#> with non-consecutive locations.
#> i Input has size 3.
#> x Subscript `5` contains non-consecutive
#> location 5.
```
|
| ```r with_df(df[is.na(df)] <- 4) #> n c li #> 1 1 e 9 #> 2 4 f 10, 11 #> 3 3 g 12, 13, 14 #> 4 4 h text ``` |
```r
with_tbl(tbl[is.na(tbl)] <- 4)
#> # A tibble: 4 x 3
#> n c li
#>
|
| ```r with_df(df[is.na(df)] <- 1:2) #> n c li #> 1 1 e 9 #> 2 1 f 10, 11 #> 3 3 g 12, 13, 14 #> 4 2 h text ``` |
```r
with_tbl(tbl[is.na(tbl)] <- 1:2)
```
```
#> Error:
#> ! Subscript `is.na(tbl)` is a matrix,
#> the data `1:2` must have size 1.
```
|
| ```r with_df(df[matrix(c(rep(TRUE, 5), rep(FALSE, 7)), ncol = 3)] <- 4) #> n c li #> 1 4 4 9 #> 2 4 f 10, 11 #> 3 4 g 12, 13, 14 #> 4 4 h text ``` |
```r
with_tbl(tbl[matrix(c(rep(TRUE, 5), rep(FALSE, 7)), ncol = 3)] <- 4)
```
```
#> Error:
#> ! Assigned data `4` must be compatible
#> with existing data.
#> i Error occurred for column `c`.
#> x Can't convert
|
| ```r with_df(df[1:2] <- matrix(8:1, ncol = 2)) #> n c li #> 1 8 4 9 #> 2 7 3 10, 11 #> 3 6 2 12, 13, 14 #> 4 5 1 text ``` |
```r
with_tbl(tbl[1:2] <- matrix(8:1, ncol = 2))
#> # A tibble: 4 x 3
#> n c li
#>
|
| ```r with_df(df[1:3, 1:2] <- matrix(6:1, ncol = 2)) #> n c li #> 1 6 3 9 #> 2 5 2 10, 11 #> 3 4 1 12, 13, 14 #> 4 NA h text ``` |
```r
with_tbl(tbl[1:3, 1:2] <- matrix(6:1, ncol = 2))
```
```
#> Error:
#> ! Assigned data `matrix(6:1, ncol = 2)`
#> must be compatible with existing data.
#> i Error occurred for column `c`.
#> x Can't convert |
| ```r with_df(df[1:2] <- array(4:1, dim = c(4, 1, 1))) #> n c li #> 1 4 4 9 #> 2 3 3 10, 11 #> 3 2 2 12, 13, 14 #> 4 1 1 text ``` |
```r
with_tbl(tbl[1:2] <- array(4:1, dim = c(4, 1, 1)))
#> # A tibble: 4 x 3
#> n c li
#>
|
| ```r with_df(df[1:2] <- array(8:1, dim = c(4, 2, 1))) #> n c li #> 1 8 4 9 #> 2 7 3 10, 11 #> 3 6 2 12, 13, 14 #> 4 5 1 text ``` |
```r
with_tbl(tbl[1:2] <- array(8:1, dim = c(4, 2, 1)))
#> # A tibble: 4 x 3
#> n c li
#>
|
| ```r with_df(df[1:2] <- array(8:1, dim = c(2, 1, 4))) #> n c li #> 1 8 4 9 #> 2 7 3 10, 11 #> 3 6 2 12, 13, 14 #> 4 5 1 text ``` |
```r
with_tbl(tbl[1:2] <- array(8:1, dim = c(2, 1, 4)))
```
```
#> Error:
#> ! `array(8:1, dim = c(2, 1, 4))` must be
#> a vector, a bare list, a data frame, a
#> matrix, or NULL.
```
|
| ```r with_df(df[1:2] <- array(8:1, dim = c(4, 1, 2))) #> n c li #> 1 8 4 9 #> 2 7 3 10, 11 #> 3 6 2 12, 13, 14 #> 4 5 1 text ``` |
```r
with_tbl(tbl[1:2] <- array(8:1, dim = c(4, 1, 2)))
```
```
#> Error:
#> ! `array(8:1, dim = c(4, 1, 2))` must be
#> a vector, a bare list, a data frame, a
#> matrix, or NULL.
```
|
| ```r with_df(df[1] <- 0) #> n c li #> 1 0 e 9 #> 2 0 f 10, 11 #> 3 0 g 12, 13, 14 #> 4 0 h text ``` |
```r
with_tbl(tbl[1] <- 0)
#> # A tibble: 4 x 3
#> n c li
#>
|
| ```r with_df(df[1] <- list(0)) #> n c li #> 1 0 e 9 #> 2 0 f 10, 11 #> 3 0 g 12, 13, 14 #> 4 0 h text ``` |
```r
with_tbl(tbl[1] <- list(0))
#> # A tibble: 4 x 3
#> n c li
#>
|
| ```r with_df(df[1] <- list(matrix(1:8, ncol = 2))) #> n.1 n.2 c li #> 1 1 5 e 9 #> 2 2 6 f 10, 11 #> 3 3 7 g 12, 13, 14 #> 4 4 8 h text ``` |
```r
with_tbl(tbl[1] <- list(matrix(1:8, ncol = 2)))
#> # A tibble: 4 x 3
#> n[,1] [,2] c li
#>
|
| ```r with_df(df[1:2] <- list(matrix(1:8, ncol = 2))) #> n.1 n.2 c.1 c.2 li #> 1 1 5 1 5 9 #> 2 2 6 2 6 10, 11 #> 3 3 7 3 7 12, 13, 14 #> 4 4 8 4 8 text ``` |
```r
with_tbl(tbl[1:2] <- list(matrix(1:8, ncol = 2)))
#> # A tibble: 4 x 3
#> n[,1] [,2] c[,1] [,2] li
#>
|
| ```r with_df(df[1] <- NULL) #> c li #> 1 e 9 #> 2 f 10, 11 #> 3 g 12, 13, 14 #> 4 h text ``` |
```r
with_tbl(tbl[1] <- NULL)
#> # A tibble: 4 x 2
#> c li
#>
|
| ```r with_df(df[, 2:3] <- NULL) #> n #> 1 1 #> 2 NA #> 3 3 #> 4 NA ``` |
```r
with_tbl(tbl[, 2:3] <- NULL)
#> # A tibble: 4 x 1
#> n
#> |
|
```r
with_df(df[1, 2:3] <- NULL)
```
```
#> Error in x[[jj]][iseq] <- vjj:
#> replacement has length zero
```
|
```r
with_tbl(tbl[1, 2:3] <- NULL)
```
```
#> Error:
#> ! `NULL` must be a vector, a bare list,
#> a data frame or a matrix.
```
|
|
```r
with_df(df[1] <- mean)
```
```
#> Error in rep(value, length.out = n):
#> attempt to replicate an object of type
#> 'closure'
```
|
```r
with_tbl(tbl[1] <- mean)
```
```
#> Error:
#> ! `mean` must be a vector, a bare list,
#> a data frame, a matrix, or NULL.
```
|
|
```r
with_df(df[1] <- lm(mpg ~ wt, data = mtcars))
```
```
#> Warning in `[<-.data.frame`(`*tmp*`,
#> 1, value = structure(list(coefficients
#> = c(`(Intercept)` = 37.285126167342, :
#> replacement element 2 has 32 rows to
#> replace 4 rows
```
```
#> Warning in `[<-.data.frame`(`*tmp*`,
#> 1, value = structure(list(coefficients
#> = c(`(Intercept)` = 37.285126167342, :
#> replacement element 3 has 32 rows to
#> replace 4 rows
```
```
#> Warning in `[<-.data.frame`(`*tmp*`,
#> 1, value = structure(list(coefficients
#> = c(`(Intercept)` = 37.285126167342, :
#> replacement element 5 has 32 rows to
#> replace 4 rows
```
```
#> Warning in `[<-.data.frame`(`*tmp*`,
#> 1, value = structure(list(coefficients
#> = c(`(Intercept)` = 37.285126167342, :
#> replacement element 7 has 5 rows to
#> replace 4 rows
```
```
#> Error in `[<-.data.frame`(`*tmp*`, 1,
#> value = structure(list(coefficients =
#> c(`(Intercept)` = 37.285126167342, :
#> replacement element 10 has 3 rows, need
#> 4
```
|
```r
with_tbl(tbl[1] <- lm(mpg ~ wt, data = mtcars))
```
```
#> Error:
#> ! `lm(mpg ~ wt, data = mtcars)` must be
#> a vector, a bare list, a data frame, a
#> matrix, or NULL.
```
|
| ```r with_df(df[2:3, ] <- df[1, ]) #> n c li #> 1 1 e 9 #> 2 1 e 9 #> 3 1 e 9 #> 4 NA h text ``` |
```r
with_tbl(tbl[2:3, ] <- tbl[1, ])
#> # A tibble: 4 x 3
#> n c li
#>
|
| ```r with_df(df[c(FALSE, TRUE, TRUE, FALSE), ] <- df[1, ]) #> n c li #> 1 1 e 9 #> 2 1 e 9 #> 3 1 e 9 #> 4 NA h text ``` |
```r
with_tbl(tbl[c(FALSE, TRUE, TRUE, FALSE), ] <- tbl[1, ])
#> # A tibble: 4 x 3
#> n c li
#>
|
| ```r with_df(df[0:2, ] <- df[1, ]) #> n c li #> 1 1 e 9 #> 2 1 e 9 #> 3 3 g 12, 13, 14 #> 4 NA h text ``` |
```r
with_tbl(tbl[0:2, ] <- tbl[1, ])
```
```
#> Error in
#> `numtbl_as_row_location_assign()`:
#> ! Must assign to rows with a valid
#> subscript vector.
#> x Subscript `0:2` can't contain `0`
#> values.
#> i It has a `0` value at location 1.
```
|
| ```r with_df(df[0, ] <- df[1, ]) #> n c li #> 1 1 e 9 #> 2 NA f 10, 11 #> 3 3 g 12, 13, 14 #> 4 NA h text ``` |
```r
with_tbl(tbl[0, ] <- tbl[1, ])
```
```
#> Error in
#> `numtbl_as_row_location_assign()`:
#> ! Must assign to rows with a valid
#> subscript vector.
#> x Subscript `0` can't contain `0`
#> values.
#> i It has a `0` value at location 1.
```
|
| ```r with_df(df[-2, ] <- df[1, ]) #> n c li #> 1 1 e 9 #> 2 NA f 10, 11 #> 3 1 e 9 #> 4 1 e 9 ``` |
```r
with_tbl(tbl[-2, ] <- tbl[1, ])
#> # A tibble: 4 x 3
#> n c li
#>
|
|
```r
with_df(df[-1:2, ] <- df[1, ])
```
```
#> Error in seq_len(nrows)[i]: only 0's may
#> be mixed with negative subscripts
```
|
```r
with_tbl(tbl[-1:2, ] <- tbl[1, ])
```
```
#> Error in
#> `numtbl_as_row_location_assign()`:
#> ! Must assign to rows with a valid
#> subscript vector.
#> x Negative and positive locations can't
#> be mixed.
#> i Subscript `-1:2` has 2 positive values
#> at locations 3 and 4.
```
|
|
```r
with_df(df[NA_integer_, ] <- df[1, ])
```
```
#> Error in `[<-.data.frame`(`*tmp*`,
#> NA_integer_, , value = structure(list(:
#> missing values are not allowed in
#> subscripted assignments of data frames
```
|
```r
with_tbl(tbl[NA_integer_, ] <- tbl[1, ])
```
```
#> Error in
#> `numtbl_as_row_location_assign()`:
#> ! Must assign to rows with a valid
#> subscript vector.
#> x Subscript `NA_integer_` can't contain
#> missing values.
#> x It has a missing value at location 1.
```
|
|
```r
with_df2(df2[NA_integer_, ] <- df2[1, ])
```
```
#> Error in `[<-.data.frame`(`*tmp*`,
#> NA_integer_, , value = structure(list(:
#> missing values are not allowed in
#> subscripted assignments of data frames
```
|
```r
with_tbl2(tbl2[NA_integer_, ] <- tbl2[1, ])
```
```
#> Error in
#> `numtbl_as_row_location_assign()`:
#> ! Must assign to rows with a valid
#> subscript vector.
#> x Subscript `NA_integer_` can't contain
#> missing values.
#> x It has a missing value at location 1.
```
|
| ```r with_df(df[TRUE, ] <- df[1, ]) #> n c li #> 1 1 e 9 #> 2 1 e 9 #> 3 1 e 9 #> 4 1 e 9 ``` |
```r
with_tbl(tbl[TRUE, ] <- tbl[1, ])
#> # A tibble: 4 x 3
#> n c li
#>
|
| ```r with_df(df[FALSE, ] <- df[1, ]) #> n c li #> 1 1 e 9 #> 2 NA f 10, 11 #> 3 3 g 12, 13, 14 #> 4 NA h text ``` |
```r
with_tbl(tbl[FALSE, ] <- tbl[1, ])
#> # A tibble: 4 x 3
#> n c li
#>
|
|
```r
with_df(df[NA, ] <- df[1, ])
```
```
#> Error in `[<-.data.frame`(`*tmp*`, NA, ,
#> value = structure(list(n = 1L, : missing
#> values are not allowed in subscripted
#> assignments of data frames
```
|
```r
with_tbl(tbl[NA, ] <- tbl[1, ])
```
```
#> Error:
#> ! Can't use NA as row index in a tibble
#> for assignment.
```
|
| ```r with_df(df[2:3, ] <- df[1, ]) #> n c li #> 1 1 e 9 #> 2 1 e 9 #> 3 1 e 9 #> 4 NA h text ``` |
```r
with_tbl(tbl[2:3, ] <- tbl[1, ])
#> # A tibble: 4 x 3
#> n c li
#>
|
| ```r with_df(df[2:3, ] <- list(df$n[1], df$c[1:2], df$li[1])) #> n c li #> 1 1 e 9 #> 2 1 e 9 #> 3 1 f 9 #> 4 NA h text ``` |
```r
with_tbl(tbl[2:3, ] <- list(tbl$n[1], tbl$c[1:2], tbl$li[1]))
#> # A tibble: 4 x 3
#> n c li
#>
|
|
```r
with_df(df[2:4, ] <- df[1:2, ])
```
```
#> Error in `[<-.data.frame`(`*tmp*`, 2:4,
#> , value = structure(list(n = c(1L, :
#> replacement element 1 has 2 rows, need 3
```
|
```r
with_tbl(tbl[2:4, ] <- tbl[1:2, ])
```
```
#> Error:
#> ! Assigned data `tbl[1:2, ]` must be
#> compatible with row subscript `2:4`.
#> x 3 rows must be assigned.
#> x Element 1 of assigned data has 2 rows.
#> i Only vectors of size 1 are recycled.
```
|
|
```r
with_df2(df2[2:4, ] <- df2[1, ])
```
```
#> Error in `[<-.data.frame`(`*tmp*`, 2:4,
#> , value = structure(list(tb =
#> structure(list(: replacement element 1
#> is a matrix/data frame of 1 row, need 3
```
|
```r
with_tbl2(tbl2[2:4, ] <- tbl2[1, ])
#> # A tibble: 4 x 2
#> tb$n $c $li m[,1] [,2]
#> |
|
```r
with_df2(df2[2:4, ] <- df2[2:3, ])
```
```
#> Error in `[<-.data.frame`(`*tmp*`, 2:4,
#> , value = structure(list(tb =
#> structure(list(: replacement element 1
#> is a matrix/data frame of 2 rows, need 3
```
|
```r
with_tbl2(tbl2[2:4, ] <- tbl2[2:3, ])
```
```
#> Error:
#> ! Assigned data `tbl2[2:3, ]` must be
#> compatible with row subscript `2:4`.
#> x 3 rows must be assigned.
#> x Element 1 of assigned data has 2 rows.
#> i Only vectors of size 1 are recycled.
```
|
| ```r with_df(df[5, ] <- df[1, ]) #> n c li #> 1 1 e 9 #> 2 NA f 10, 11 #> 3 3 g 12, 13, 14 #> 4 NA h text #> 5 1 e 9 ``` |
```r
with_tbl(tbl[5, ] <- tbl[1, ])
#> # A tibble: 5 x 3
#> n c li
#>
|
| ```r with_df(df[5:7, ] <- df[1, ]) #> n c li #> 1 1 e 9 #> 2 NA f 10, 11 #> 3 3 g 12, 13, 14 #> 4 NA h text #> 5 1 e 9 #> 6 1 e 9 #> 7 1 e 9 ``` |
```r
with_tbl(tbl[5:7, ] <- tbl[1, ])
#> # A tibble: 7 x 3
#> n c li
#>
|
|
```r
with_df(df[6, ] <- df[1, ])
#> n c li
#> 1 1 e 9
#> 2 NA f 10, 11
#> 3 3 g 12, 13, 14
#> 4 NA h text
#> 5 NA |
```r
with_tbl(tbl[6, ] <- tbl[1, ])
```
```
#> Error in
#> `numtbl_as_row_location_assign()`:
#> ! Can't assign to rows beyond the end
#> with non-consecutive locations.
#> i Input has size 4.
#> x Subscript `6` contains non-consecutive
#> location 6.
```
|
| ```r with_df(df[-5, ] <- df[1, ]) #> n c li #> 1 1 e 9 #> 2 1 e 9 #> 3 1 e 9 #> 4 1 e 9 ``` |
```r
with_tbl(tbl[-5, ] <- tbl[1, ])
```
```
#> Error in
#> `numtbl_as_row_location_assign()`:
#> ! Can't negate rows past the end.
#> i Location 5 doesn't exist.
#> i There are only 4 rows.
```
|
| ```r with_df(df[-(5:7), ] <- df[1, ]) #> n c li #> 1 1 e 9 #> 2 1 e 9 #> 3 1 e 9 #> 4 1 e 9 ``` |
```r
with_tbl(tbl[-(5:7), ] <- tbl[1, ])
```
```
#> Error in
#> `numtbl_as_row_location_assign()`:
#> ! Can't negate rows past the end.
#> i Locations 5, 6, and 7 don't exist.
#> i There are only 4 rows.
```
|
| ```r with_df(df[-6, ] <- df[1, ]) #> n c li #> 1 1 e 9 #> 2 1 e 9 #> 3 1 e 9 #> 4 1 e 9 ``` |
```r
with_tbl(tbl[-6, ] <- tbl[1, ])
```
```
#> Error in
#> `numtbl_as_row_location_assign()`:
#> ! Can't negate rows past the end.
#> i Location 6 doesn't exist.
#> i There are only 4 rows.
```
|
| ```r with_df(df[as.character(1:3), ] <- df[1, ]) #> n c li #> 1 1 e 9 #> 2 1 e 9 #> 3 1 e 9 #> 4 NA h text ``` |
```r
with_tbl(tbl[as.character(1:3), ] <- tbl[1, ])
#> # A tibble: 4 x 3
#> n c li
#>
|
| ```r with_df(df[as.character(-(1:3)), ] <- df[1, ]) #> n c li #> 1 1 e 9 #> 2 NA f 10, 11 #> 3 3 g 12, 13, 14 #> 4 NA h text #> -1 1 e 9 #> -2 1 e 9 #> -3 1 e 9 ``` |
```r
with_tbl(tbl[as.character(-(1:3)), ] <- tbl[1, ])
```
```
#> Warning: The `i` argument of `[.tbl_df`
#> must use valid row names as of tibble
#> 3.0.0.
#> Use `NA_integer_` as row index to obtain
#> a row full of `NA` values.
```
```
#> Error:
#> ! Can't use NA as row index in a tibble
#> for assignment.
```
|
| ```r with_df(df[as.character(3:5), ] <- df[1, ]) #> n c li #> 1 1 e 9 #> 2 NA f 10, 11 #> 3 1 e 9 #> 4 1 e 9 #> 5 1 e 9 ``` |
```r
with_tbl(tbl[as.character(3:5), ] <- tbl[1, ])
```
```
#> Warning: The `i` argument of `[.tbl_df`
#> must use valid row names as of tibble
#> 3.0.0.
#> Use `NA_integer_` as row index to obtain
#> a row full of `NA` values.
```
```
#> Error:
#> ! Can't use NA as row index in a tibble
#> for assignment.
```
|
| ```r with_df(df[as.character(-(3:5)), ] <- df[1, ]) #> n c li #> 1 1 e 9 #> 2 NA f 10, 11 #> 3 3 g 12, 13, 14 #> 4 NA h text #> -3 1 e 9 #> -4 1 e 9 #> -5 1 e 9 ``` |
```r
with_tbl(tbl[as.character(-(3:5)), ] <- tbl[1, ])
```
```
#> Warning: The `i` argument of `[.tbl_df`
#> must use valid row names as of tibble
#> 3.0.0.
#> Use `NA_integer_` as row index to obtain
#> a row full of `NA` values.
```
```
#> Error:
#> ! Can't use NA as row index in a tibble
#> for assignment.
```
|
|
```r
with_df(df[NA_character_, ] <- df[1, ])
```
```
#> Error in `[<-.data.frame`(`*tmp*`,
#> NA_character_, , value =
#> structure(list(: missing values are not
#> allowed in subscripted assignments of
#> data frames
```
|
```r
with_tbl(tbl[NA_character_, ] <- tbl[1, ])
```
```
#> Error:
#> ! Can't use NA as row index in a tibble
#> for assignment.
```
|
|
```r
with_df(df[2:3, 1] <- df[1:2, 2])
#> n c li
#> 1 1 e 9
#> 2 e f 10, 11
#> 3 f g 12, 13, 14
#> 4 |
```r
with_tbl(tbl[2:3, 1] <- tbl[1:2, 2])
```
```
#> Error:
#> ! Assigned data `tbl[1:2, 2]` must be
#> compatible with existing data.
#> i Error occurred for column `n`.
#> x Can't convert |
|
```r
with_df(df[2:3, 2] <- df[1:2, 3])
```
```
#> Warning in `[<-.data.frame`(`*tmp*`,
#> 2:3, 2, value = list(9, 10:11)):
#> provided 2 variables to replace 1
#> variables
```
```
#> n c li
#> 1 1 e 9
#> 2 NA 9 10, 11
#> 3 3 9 12, 13, 14
#> 4 NA h text
```
|
```r
with_tbl(tbl[2:3, 2] <- tbl[1:2, 3])
```
```
#> Error:
#> ! Assigned data `tbl[1:2, 3]` must be
#> compatible with existing data.
#> i Error occurred for column `c`.
#> x Can't convert
|
|
```r
with_df(df[2:3, 3] <- df2[1:2, 1])
```
```
#> Warning in `[<-.data.frame`(`*tmp*`,
#> 2:3, 3, value = structure(list(n =
#> c(1L, : provided 3 variables to replace
#> 1 variables
```
```
#> n c li
#> 1 1 e 9
#> 2 NA f 1
#> 3 3 g NA
#> 4 NA h text
```
|
```r
with_tbl(tbl[2:3, 3] <- tbl2[1:2, 1])
```
```
#> Error in `df_cast_opts()`:
#> ! Data frame must have names.
#> i In file 'type-data-frame.c' at line
#> 683.
#> i This is an internal error in the vctrs
#> package, please report it to the package
#> authors.
```
|
|
```r
with_df2(df2[2:3, 1] <- df2[1:2, 2])
```
```
#> Warning in matrix(value, n, p): data
#> length [8] is not a sub-multiple or
#> multiple of the number of columns [3]
```
```
#> tb.n tb.c tb.li m.1 m.2 m.3 m.4
#> 1 1 e 9 1 0 0 0
#> 2 1 0 0 0 1 0 0
#> 3 0 1 0 0 0 1 0
#> 4 NA h text 0 0 0 1
```
|
```r
with_tbl2(tbl2[2:3, 1] <- tbl2[1:2, 2])
```
```
#> Error:
#> ! Assigned data `tbl2[1:2, 2]` must be
#> compatible with existing data.
#> i Error occurred for column `tb`.
#> x Can't convert |
| ```r with_df2(df2[2:3, 2] <- df[1:2, 1]) #> tb.n tb.c tb.li m.1 m.2 m.3 m.4 #> 1 1 e 9 1 0 0 0 #> 2 NA f 10, 11 1 1 1 1 #> 3 3 g 12, 13, 14 NA NA NA NA #> 4 NA h text 0 0 0 1 ``` |
```r
with_tbl2(tbl2[2:3, 2] <- tbl[1:2, 1])
#> # A tibble: 4 x 2
#> tb$n $c $li m[,1] [,2]
#> |
| ```r with_df({df$x <- NA; df[2:3, "x"] <- 3:2}) #> n c li x #> 1 1 e 9 NA #> 2 NA f 10, 11 3 #> 3 3 g 12, 13, 14 2 #> 4 NA h text NA ``` |
```r
with_tbl({tbl$x <- NA; tbl[2:3, "x"] <- 3:2})
#> # A tibble: 4 x 4
#> n c li x
#> |
|
```r
with_df({df[2:3, 2:3] <- NA})
#> n c li
#> 1 1 e 9
#> 2 NA |
```r
with_tbl({tbl[2:3, 2:3] <- NA})
#> # A tibble: 4 x 3
#> n c li
#>
|
| ```r with_df({df$x <- NA_integer_; df[2:3, "x"] <- 3:2}) #> n c li x #> 1 1 e 9 NA #> 2 NA f 10, 11 3 #> 3 3 g 12, 13, 14 2 #> 4 NA h text NA ``` |
```r
with_tbl({tbl$x <- NA_integer_; tbl[2:3, "x"] <- 3:2})
#> # A tibble: 4 x 4
#> n c li x
#> |
| ```r with_df(df[2:3, "n"] <- 1) #> n c li #> 1 1 e 9 #> 2 1 f 10, 11 #> 3 1 g 12, 13, 14 #> 4 NA h text ``` |
```r
with_tbl(tbl[2:3, "n"] <- 1)
#> # A tibble: 4 x 3
#> n c li
#>
|
| ```r with_df(df[2:3, "x"] <- 1) #> n c li x #> 1 1 e 9 NA #> 2 NA f 10, 11 1 #> 3 3 g 12, 13, 14 1 #> 4 NA h text NA ``` |
```r
with_tbl(tbl[2:3, "x"] <- 1)
#> # A tibble: 4 x 4
#> n c li x
#> |
|
```r
with_df(df[2:3, "n"] <- NULL)
```
```
#> Error in x[[jj]][iseq] <- vjj:
#> replacement has length zero
```
|
```r
with_tbl(tbl[2:3, "n"] <- NULL)
```
```
#> Error:
#> ! `NULL` must be a vector, a bare list,
#> a data frame or a matrix.
```
|
|
```r
with_df(df[5, "n"] <- list(0L))
#> n c li
#> 1 1 e 9
#> 2 NA f 10, 11
#> 3 3 g 12, 13, 14
#> 4 NA h text
#> 5 0 |
```r
with_tbl(tbl[5, "n"] <- list(0L))
#> # A tibble: 5 x 3
#> n c li
#>
|
| ```r with_df(df[[1, 1]] <- 0) #> n c li #> 1 0 e 9 #> 2 NA f 10, 11 #> 3 3 g 12, 13, 14 #> 4 NA h text ``` |
```r
with_tbl(tbl[[1, 1]] <- 0)
#> # A tibble: 4 x 3
#> n c li
#>
|
| ```r with_df(df[1, ][[1]] <- 0) #> n c li #> 1 0 e 9 #> 2 NA f 10, 11 #> 3 3 g 12, 13, 14 #> 4 NA h text ``` |
```r
with_tbl(tbl[1, ][[1]] <- 0)
#> # A tibble: 4 x 3
#> n c li
#>
|
| ```r with_df(df[[1, 3]] <- list(NULL)) #> n c li #> 1 1 e NULL #> 2 NA f 10, 11 #> 3 3 g 12, 13, 14 #> 4 NA h text ``` |
```r
with_tbl(tbl[[1, 3]] <- list(NULL))
#> # A tibble: 4 x 3
#> n c li
#>
|
| ```r with_df(df[1, ][[3]] <- list(NULL)) #> n c li #> 1 1 e NULL #> 2 NA f 10, 11 #> 3 3 g 12, 13, 14 #> 4 NA h text ``` |
```r
with_tbl(tbl[1, ][[3]] <- list(NULL))
#> # A tibble: 4 x 3
#> n c li
#>
|
|
```r
with_df2(df2[[1, 1]] <- df[1, ])
```
```
#> Error in `[[<-.data.frame`(`*tmp*`,
#> iseq, value = structure(list(n = 1L, :
#> replacement has 1 row, data has 4
```
|
```r
with_tbl2(tbl2[[1, 1]] <- tbl[1, ])
#> # A tibble: 4 x 2
#> tb$n $c $li m[,1] [,2]
#> |
| ```r with_df2(df2[1, ][[1]] <- df[1, ]) #> tb.n tb.c tb.li m.1 m.2 m.3 m.4 #> 1 1 e 9 1 0 0 0 #> 2 NA f 10, 11 0 1 0 0 #> 3 3 g 12, 13, 14 0 0 1 0 #> 4 NA h text 0 0 0 1 ``` |
```r
with_tbl2(tbl2[1, ][[1]] <- tbl[1, ])
#> # A tibble: 4 x 2
#> tb$n $c $li m[,1] [,2]
#> |
|
```r
with_df2(df2[[1, 2]] <- t(1:4))
```
```
#> Error in x[[jseq]][[iseq]] <- value:
#> more elements supplied than there are to
#> replace
```
|
```r
with_tbl2(tbl2[[1, 2]] <- t(1:4))
#> # A tibble: 4 x 2
#> tb$n $c $li m[,1] [,2]
#> |
| ```r with_df2(df2[1, ][[2]] <- t(1:4)) #> tb.n tb.c tb.li m.1 m.2 m.3 m.4 #> 1 1 e 9 1 2 3 4 #> 2 NA f 10, 11 0 1 0 0 #> 3 3 g 12, 13, 14 0 0 1 0 #> 4 NA h text 0 0 0 1 ``` |
```r
with_tbl2(tbl2[1, ][[2]] <- t(1:4))
#> # A tibble: 4 x 2
#> tb$n $c $li m[,1] [,2]
#> |
|
```r
df[[1:2, 1]]
```
```
#> Error in col[[i, exact = exact]]:
#> attempt to select more than one element
#> in vectorIndex
```
|
```r
tbl[[1:2, 1]]
```
```
#> Error in `vectbl_as_row_location2()`:
#> ! Must extract row with a single valid
#> subscript.
#> x Subscript `1:2` has size 2 but must be
#> size 1.
```
|
|
```r
with_df(df[[1:2, 1]] <- 0)
```
```
#> Error in `[[<-.data.frame`(`*tmp*`, 1:2,
#> 1, value = 0): only a single element
#> should be replaced
```
|
```r
with_tbl(tbl[[1:2, 1]] <- 0)
```
```
#> Error in `vectbl_as_row_location2()`:
#> ! Must assign to row with a single valid
#> subscript.
#> x Subscript `1:2` has size 2 but must be
#> size 1.
```
|