diff --git a/R/dftbl.R b/R/dftbl.R
index 483933ed7..5b11a0ce6 100644
--- a/R/dftbl.R
+++ b/R/dftbl.R
@@ -5,8 +5,6 @@ set_dftbl_hooks <- function() {
set_dftbl_knit_hook(width)
set_dftbl_source_hook()
set_dftbl_chunk_hook()
- set_dftbl_error_hook()
- set_dftbl_warning_hook()
}
# Defines a `dftbl` knitr option. If this chunk option is set, code is duplicated
@@ -148,41 +146,3 @@ set_dftbl_chunk_hook <- function() {
knitr::knit_hooks$set(chunk = dftbl_chunk_hook)
}
-
-# I don't understand why knitr doesn't wrap error output.
-set_dftbl_error_hook <- function() {
- # Need to use a closure here to daisy-chain hooks
-
- old_error_hook <- knitr::knit_hooks$get("error")
-
- dftbl_error_hook <- function(x, options) {
- if (isTRUE(options$dftbl)) {
- x <- strsplit(x, "\n", fixed = TRUE)[[1]]
- x <- unlist(map(x, fansi::strwrap_sgr, getOption("width") + 4, prefix = "#> ", initial = ""))
- x <- paste(paste0(x, "\n"), collapse = "")
- }
- x <- old_error_hook(x, options)
- paste0('
-
-```
-#> 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.
-```
-
-
-
-```
+#> 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
```
@@ -343,32 +330,19 @@ tbl[[1:2]]
```r
df[[c("n", "c")]]
+#> Error in .subset2(x, i, exact = exact): subscript out of bounds
```
-
-
-```
-#> Error in .subset2(x, i, exact = exact):
-#> subscript out of bounds
-```
-
-
-
-```
#> Error in `vectbl_as_col_location2()`:
-#> ! Must extract column with a single
-#> valid subscript.
+#> ! Must extract column with a single valid subscript.
#> x Subscript `NA` can't be `NA`.
```
-
-
-```
#> Warning: Unknown or uninitialised
#> column: `not_present`.
-```
-
-
-
-```
#> NULL
```
@@ -926,18 +798,10 @@ df[!is.na(df)]
```r
tbl[!is.na(tbl)]
-```
-
-
-
-```
#> Error in `vectbl_as_col_location2()`:
-#> ! Must assign to column with a single
-#> valid subscript.
-#> x Subscript `TRUE` has the wrong type
-#> `logical`.
+#> ! Must assign to column with a single valid subscript.
+#> x Subscript `TRUE` has the wrong type `logical`.
#> i It must be numeric or character.
```
-
-
-```
-#> Error in `[[<-.data.frame`(`*tmp*`,
-#> "tb", value = structure(list(n = 1L, :
-#> replacement has 1 row, data has 4
-```
-
-
-
-```
#> 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 0
@@ -2171,22 +1823,12 @@ with_df(df[[5]] <- 0)
```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.
+#> 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.
+#> x Subscript `5` contains non-consecutive location 5.
```
-
-
@@ -2620,19 +2262,9 @@ with_tbl(tbl[1:2] <- list(1))
```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
@@ -2644,17 +2276,11 @@ with_df(df[1:2] <- list(0, 0, 0))
```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.
+#> ! Can't recycle `list(0, 0, 0)` (size 3) to size 2.
```
-
+ |
```r
with_df(df[1:3] <- list(0, 0))
@@ -2669,18 +2295,10 @@ with_df(df[1:3] <- list(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.
+#> ! Can't recycle `list(0, 0)` (size 2) to size 3.
```
-
-
|
An attempt to update the same column twice gives an error.
@@ -2689,32 +2307,17 @@ An attempt to update the same column twice gives an error.
```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
```
-
-
-```
-#> 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.
+#> ! Column index 1 is used more than once for assignment.
```
-
-
|
If `a` contains `NULL` values, the corresponding columns are removed *after* updating (i.e. position indexes refer to columns before any modifications).
@@ -2751,91 +2354,47 @@ with_tbl(tbl[1:2] <- list(NULL, 4:1))
```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
```
-
-
-```
-#> 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.
+#> ! 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
```
-
-
-```
-#> 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.
+#> ! 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
```
-
-
-```
-#> 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.
+#> ! Can't use NA as column index in a tibble for assignment.
```
-
-
|
Just like column updates, `[<-` supports changing the type of an existing column.
@@ -3043,36 +2602,19 @@ with_tbl(tbl[4] <- list(4:1))
```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
```
-
-
-```
-#> 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.
+#> 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.
+#> x Subscript `5` contains non-consecutive location 5.
```
-
-
|
Tibbles support indexing by a logical matrix, but only for a scalar RHS, and if all columns updated are compatible with the value assigned.
@@ -3116,17 +2658,11 @@ with_df(df[is.na(df)] <- 1:2)
```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.
+#> ! 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)
@@ -3141,20 +2677,12 @@ with_df(df[matrix(c(rep(TRUE, 5), rep(FALSE, 7)), ncol = 3)] <- 4)
```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.
+#> ! Assigned data `4` must be compatible with existing data.
#> i Error occurred for column `c`.
#> x Can't convert to .
```
-
-
|
### `a` is a matrix or array
@@ -3202,20 +2730,13 @@ with_df(df[1:3, 1:2] <- matrix(6:1, ncol = 2))
```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.
+#> ! Assigned data `matrix(6:1, ncol = 2)` must be compatible with existing data.
#> i Error occurred for column `c`.
-#> x Can't convert to
-#> .
+#> x Can't convert to .
```
-
+ |
```r
with_df(df[1:2] <- array(4:1, dim = c(4, 1, 1)))
@@ -3278,18 +2799,11 @@ with_df(df[1:2] <- array(8:1, dim = c(2, 1, 4)))
```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.
+#> ! `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)))
@@ -3304,19 +2818,10 @@ with_df(df[1:2] <- array(8:1, dim = c(4, 1, 2)))
```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.
+#> ! `array(8:1, dim = c(4, 1, 2))` must be a vector, a bare list, a data frame, a matrix, or NULL.
```
-
-
|
### `a` is another type of vector
@@ -3489,31 +2994,17 @@ with_tbl(tbl[, 2:3] <- NULL)
```r
with_df(df[1, 2:3] <- NULL)
+#> Error in x[[jj]][iseq] <- vjj: replacement has length zero
```
-
-
-```
-#> 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.
+#> ! `NULL` must be a vector, a bare list, a data frame or a matrix.
```
-
-
|
### `a` is not a vector
@@ -3526,103 +3017,52 @@ See `?vec_is` and `?vec_proxy` for details.
```r
with_df(df[1] <- mean)
+#> Error in rep(value, length.out = n): attempt to replicate an object of type 'closure'
```
-
-
-```
-#> 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.
+#> ! `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
```
-
-
-```
-#> 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.
+#> ! `lm(mpg ~ wt, data = mtcars)` must be a vector, a bare list, a data frame, a matrix, or NULL.
```
-
-
|
@@ -3698,21 +3138,13 @@ with_df(df[0:2, ] <- df[1, ])
```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.
+#> 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, ])
@@ -3727,21 +3159,13 @@ with_df(df[0, ] <- df[1, ])
```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.
+#> 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, ])
@@ -3769,101 +3193,54 @@ with_tbl(tbl[-2, ] <- tbl[1, ])
```r
with_df(df[-1:2, ] <- df[1, ])
+#> Error in seq_len(nrows)[i]: only 0's may be mixed with negative subscripts
```
-
-
-```
-#> 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.
```
-
-
-```
-#> 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
```
-
-
-```
-#> 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.
+#> 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
```
-
-
-```
-#> 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.
+#> 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, ])
@@ -3915,33 +3292,17 @@ with_tbl(tbl[FALSE, ] <- tbl[1, ])
```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
```
-
-
-```
-#> 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.
+#> ! Can't use NA as row index in a tibble for assignment.
```
-
-
|
Only values of size one can be recycled.
@@ -3998,53 +3359,30 @@ with_tbl(tbl[2:3, ] <- list(tbl$n[1], tbl$c[1:2], tbl$li[1]))
```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
```
-
-
-```
-#> 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`.
+#> ! 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
```
-
-
-```
-#> 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, ])
@@ -4063,36 +3401,20 @@ with_tbl2(tbl2[2:4, ] <- tbl2[1, ])
```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
```
-
-
-```
-#> 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`.
+#> ! 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.
```
-
-
|
For compatibility, only a warning is issued for indexing beyond the number of rows.
@@ -4171,21 +3493,13 @@ with_df(df[6, ] <- df[1, ])
```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.
+#> 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.
+#> x Subscript `6` contains non-consecutive location 6.
```
-
+ |
```r
with_df(df[-5, ] <- df[1, ])
@@ -4200,19 +3514,13 @@ with_df(df[-5, ] <- df[1, ])
```r
with_tbl(tbl[-5, ] <- tbl[1, ])
-```
-
-
-
-```
-#> Error in
-#> `numtbl_as_row_location_assign()`:
+#> 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, ])
@@ -4227,19 +3535,13 @@ with_df(df[-(5:7), ] <- df[1, ])
```r
with_tbl(tbl[-(5:7), ] <- tbl[1, ])
-```
-
-
-
-```
-#> Error in
-#> `numtbl_as_row_location_assign()`:
+#> 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, ])
@@ -4254,20 +3556,12 @@ with_df(df[-6, ] <- df[1, ])
```r
with_tbl(tbl[-6, ] <- tbl[1, ])
-```
-
-
-
-```
-#> Error in
-#> `numtbl_as_row_location_assign()`:
+#> 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.
```
-
-
|
For compatibility, `i` can also be a character vector containing positive numbers.
@@ -4316,27 +3610,13 @@ with_df(df[as.character(-(1:3)), ] <- df[1, ])
```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.
-```
-
-
-
-```
+#> 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.
+#> ! Can't use NA as row index in a tibble for assignment.
```
-
+ |
```r
with_df(df[as.character(3:5), ] <- df[1, ])
@@ -4352,27 +3632,13 @@ with_df(df[as.character(3:5), ] <- df[1, ])
```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.
-```
-
-
-
-```
+#> 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.
+#> ! Can't use NA as row index in a tibble for assignment.
```
- |
+ |
```r
with_df(df[as.character(-(3:5)), ] <- df[1, ])
@@ -4390,58 +3656,27 @@ with_df(df[as.character(-(3:5)), ] <- df[1, ])
```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.
-```
-
-
-
-```
+#> 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.
+#> ! 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
```
-
-
-```
-#> 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.
+#> ! Can't use NA as row index in a tibble for assignment.
```
-
-
|
## Row and column subassignment
@@ -4471,37 +3706,20 @@ with_df(df[2:3, 1] <- df[1:2, 2])
```r
with_tbl(tbl[2:3, 1] <- tbl[1:2, 2])
-```
-
-
-
-```
#> Error:
-#> ! Assigned data `tbl[1:2, 2]` must be
-#> compatible with existing data.
+#> ! Assigned data `tbl[1:2, 2]` must be compatible with existing data.
#> i Error occurred for column `n`.
-#> x Can't convert to
-#> .
+#> x Can't convert to .
```
-
+ |
```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
@@ -4513,36 +3731,20 @@ with_df(df[2:3, 2] <- df[1:2, 3])
```r
with_tbl(tbl[2:3, 2] <- tbl[1:2, 3])
-```
-
-
-
-```
#> Error:
-#> ! Assigned data `tbl[1:2, 3]` must be
-#> compatible with existing data.
+#> ! Assigned data `tbl[1:2, 3]` must be compatible with existing data.
#> i Error occurred for column `c`.
#> x Can't convert to .
```
- |
+ |
```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
@@ -4554,37 +3756,19 @@ with_df(df[2:3, 3] <- df2[1:2, 1])
```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.
+#> 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
@@ -4596,20 +3780,13 @@ with_df2(df2[2:3, 1] <- df2[1:2, 2])
```r
with_tbl2(tbl2[2:3, 1] <- tbl2[1:2, 2])
-```
-
-
-
-```
#> Error:
-#> ! Assigned data `tbl2[1:2, 2]` must be
-#> compatible with existing data.
+#> ! Assigned data `tbl2[1:2, 2]` must be compatible with existing data.
#> i Error occurred for column `tb`.
-#> x Can't convert to
-#> .
+#> x Can't convert to .
```
- |
+ |
```r
with_df2(df2[2:3, 2] <- df[1:2, 1])
@@ -4772,31 +3949,17 @@ with_tbl(tbl[2:3, "x"] <- 1)
```r
with_df(df[2:3, "n"] <- NULL)
+#> Error in x[[jj]][iseq] <- vjj: replacement has length zero
```
-
-
-```
-#> 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.
+#> ! `NULL` must be a vector, a bare list, a data frame or a matrix.
```
-
-
|
Likewise, for new rows, `x[i, j] <- a` fills the unassigned columns with `NA`.
@@ -4939,17 +4102,10 @@ with_tbl(tbl[1, ][[3]] <- list(NULL))
```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
```
-
-
-```
-#> 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, ])
@@ -4994,17 +4150,10 @@ with_tbl2(tbl2[1, ][[1]] <- tbl[1, ])
```r
with_df2(df2[[1, 2]] <- t(1:4))
+#> Error in x[[jseq]][[iseq]] <- value: more elements supplied than there are to replace
```
-
-
-```
-#> Error in x[[jseq]][[iseq]] <- value:
-#> more elements supplied than there are to
-#> replace
-```
-
- |
+ |
```r
with_tbl2(tbl2[[1, 2]] <- t(1:4))
@@ -5049,64 +4198,34 @@ with_tbl2(tbl2[1, ][[2]] <- t(1:4))
```r
df[[1:2, 1]]
+#> Error in col[[i, exact = exact]]: attempt to select more than one element in vectorIndex
```
-
-
-```
-#> 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.
+#> ! 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
```
-
-
-```
-#> 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.
+#> ! Must assign to row with a single valid subscript.
+#> x Subscript `1:2` has size 2 but must be size 1.
```
-
-
|
NB: `vec_size(a)` must equal 1.