|
557 | 557 | `NULL` must be a vector, a bare list, a data frame or a matrix. |
558 | 558 | Code |
559 | 559 | # # [<-.tbl_df and overwriting NA |
560 | | - df <- tibble(x = rep(NA, 3)) |
| 560 | + df <- tibble(x = rep(NA, 3), z = matrix(NA, ncol = 2, dimnames = list(NULL, c( |
| 561 | + "a", "b")))) |
561 | 562 | df[1, "x"] <- 5 |
562 | | - Error <tibble_error_assign_incompatible_type> |
563 | | - Assigned data `5` must be compatible with existing data. |
564 | | - i Error occurred for column `x`. |
565 | | - x Can't convert from <double> to <logical> due to loss of precision. |
566 | | - * Locations: 1. |
| 563 | + df[1, "z"] <- 5 |
| 564 | + df |
| 565 | + Output |
| 566 | + # A tibble: 3 x 2 |
| 567 | + x z[,"a"] [,"b"] |
| 568 | + <dbl> <dbl> <dbl> |
| 569 | + 1 5 5 5 |
| 570 | + 2 NA NA NA |
| 571 | + 3 NA NA NA |
| 572 | + Code |
| 573 | + # # [<-.tbl_df and overwriting with NA |
| 574 | + df <- tibble(a = TRUE, b = 1L, c = sqrt(2), d = 0+3i + 1, e = "e", f = raw(1), |
| 575 | + g = tibble(x = 1, y = 1), h = matrix(1:3, nrow = 1)) |
| 576 | + df[FALSE, "a"] <- NA |
| 577 | + df[FALSE, "b"] <- NA |
| 578 | + df[FALSE, "c"] <- NA |
| 579 | + df[FALSE, "d"] <- NA |
| 580 | + df[FALSE, "e"] <- NA |
| 581 | + df[FALSE, "f"] <- NA |
| 582 | + df[FALSE, "g"] <- NA |
| 583 | + df[FALSE, "h"] <- NA |
| 584 | + df |
| 585 | + Output |
| 586 | + # A tibble: 1 x 8 |
| 587 | + a b c d e f g$x $y h[,1] [,2] [,3] |
| 588 | + <lgl> <int> <dbl> <cpl> <chr> <raw> <dbl> <dbl> <int> <int> <int> |
| 589 | + 1 TRUE 1 1.41 1+3i e 00 1 1 1 2 3 |
| 590 | + Code |
| 591 | + df[integer(), "a"] <- NA |
| 592 | + df[integer(), "b"] <- NA |
| 593 | + df[integer(), "c"] <- NA |
| 594 | + df[integer(), "d"] <- NA |
| 595 | + df[integer(), "e"] <- NA |
| 596 | + df[integer(), "f"] <- NA |
| 597 | + df[integer(), "g"] <- NA |
| 598 | + df[integer(), "h"] <- NA |
| 599 | + df |
| 600 | + Output |
| 601 | + # A tibble: 1 x 8 |
| 602 | + a b c d e f g$x $y h[,1] [,2] [,3] |
| 603 | + <lgl> <int> <dbl> <cpl> <chr> <raw> <dbl> <dbl> <int> <int> <int> |
| 604 | + 1 TRUE 1 1.41 1+3i e 00 1 1 1 2 3 |
| 605 | + Code |
| 606 | + df[1, "a"] <- NA |
| 607 | + df[1, "b"] <- NA |
| 608 | + df[1, "c"] <- NA |
| 609 | + df[1, "d"] <- NA |
| 610 | + df[1, "e"] <- NA |
| 611 | + df[1, "f"] <- NA |
| 612 | + df[1, "g"] <- NA |
| 613 | + df[1, "h"] <- NA |
| 614 | + df |
| 615 | + Output |
| 616 | + # A tibble: 1 x 8 |
| 617 | + a b c d e f g$x $y h[,1] [,2] [,3] |
| 618 | + <lgl> <int> <dbl> <cpl> <chr> <raw> <dbl> <dbl> <int> <int> <int> |
| 619 | + 1 NA NA NA NA <NA> 00 NA NA NA NA NA |
567 | 620 | Code |
568 | 621 | # # [<-.tbl_df and matrix subsetting |
569 | 622 | foo <- tibble(a = 1:3, b = letters[1:3]) |
|
0 commit comments