| 1 | # vars_select() type-checks inputs |
| 2 | |
| 3 | Code |
| 4 | vars_select(letters, TRUE) |
| 5 | Condition |
| 6 | Error: |
| 7 | ! Can't select columns with `TRUE`. |
| 8 | x `TRUE` must be numeric or character, not `TRUE`. |
| 9 | Code |
| 10 | vars_select(letters, 2.5) |
| 11 | Condition |
| 12 | Error: |
| 13 | ! Can't select columns with `2.5`. |
| 14 | x Can't convert from `2.5` <double> to <integer> due to loss of precision. |
| 15 | Code |
| 16 | vars_select(letters, structure(1:3, class = "tidysel_foobar")) |
| 17 | Condition |
| 18 | Error: |
| 19 | ! Can't select columns with `structure(1:3, class = "tidysel_foobar")`. |
| 20 | x `structure(1:3, class = "tidysel_foobar")` must be numeric or character, not a <tidysel_foobar> object. |
| 21 | |
| 22 | # vars_select() has consistent location errors |
| 23 | |
| 24 | Code |
| 25 | # Bare names |
| 26 | vars_select(letters, foo) |
| 27 | Condition |
| 28 | Error: |
| 29 | ! Can't select columns that don't exist. |
| 30 | x Column `foo` doesn't exist. |
| 31 | Code |
| 32 | vars_select(letters, -foo) |
| 33 | Condition |
| 34 | Error: |
| 35 | ! Can't select columns that don't exist. |
| 36 | x Column `foo` doesn't exist. |
| 37 | Code |
| 38 | # Names |
| 39 | vars_select(letters, "foo") |
| 40 | Condition |
| 41 | Error: |
| 42 | ! Can't select columns that don't exist. |
| 43 | x Column `foo` doesn't exist. |
| 44 | Code |
| 45 | vars_select(letters, a:"foo") |
| 46 | Condition |
| 47 | Error: |
| 48 | ! Can't select columns that don't exist. |
| 49 | x Column `foo` doesn't exist. |
| 50 | Code |
| 51 | # Locations |
| 52 | vars_select(letters, 30, 50, 100) |
| 53 | Condition |
| 54 | Error: |
| 55 | ! Can't select columns past the end. |
| 56 | i Locations 30, 50, and 100 don't exist. |
| 57 | i There are only 26 columns. |
| 58 | Code |
| 59 | vars_select(letters, -100) |
| 60 | Condition |
| 61 | Error: |
| 62 | ! Can't select columns past the end. |
| 63 | i Location 100 doesn't exist. |
| 64 | i There are only 26 columns. |
| 65 | Code |
| 66 | vars_select(letters, !100) |
| 67 | Condition |
| 68 | Error: |
| 69 | ! Can't select columns past the end. |
| 70 | i Location 100 doesn't exist. |
| 71 | i There are only 26 columns. |
| 72 | |
| 73 | # when .strict = FALSE, vars_rename always succeeds |
| 74 | |
| 75 | Code |
| 76 | vars_rename(c("a", "b"), d = e, .strict = TRUE) |
| 77 | Condition |
| 78 | Error: |
| 79 | ! Can't rename columns that don't exist. |
| 80 | x Column `e` doesn't exist. |
| 81 | Code |
| 82 | vars_rename(c("a", "b"), d = e, f = g, .strict = TRUE) |
| 83 | Condition |
| 84 | Error: |
| 85 | ! Can't rename columns that don't exist. |
| 86 | x Column `e` doesn't exist. |
| 87 | Code |
| 88 | vars_rename(c("a", "b"), d = "e", f = "g", .strict = TRUE) |
| 89 | Condition |
| 90 | Error: |
| 91 | ! Can't rename columns that don't exist. |
| 92 | x Column `e` doesn't exist. |
| 93 | |
| 94 | # vars_rename() disallows renaming to same column |
| 95 | |
| 96 | Code |
| 97 | # New column |
| 98 | vars_rename(c("a", "b", "c"), foo = a, foo = b) |
| 99 | Condition |
| 100 | Error: |
| 101 | ! Names must be unique. |
| 102 | x These names are duplicated: |
| 103 | * "foo" at locations 1 and 2. |
| 104 | Code |
| 105 | # Existing column |
| 106 | vars_rename(c("a", "b", "c"), c = a, c = b) |
| 107 | Condition |
| 108 | Error: |
| 109 | ! Names must be unique. |
| 110 | x These names are duplicated: |
| 111 | * "c" at locations 1, 2, and 3. |
| 112 | |
| 113 | # vars_rename() disallows renaming to existing columns (#70) |
| 114 | |
| 115 | Code |
| 116 | # One column |
| 117 | vars_rename(c("a", "b", "c"), b = a) |
| 118 | Condition |
| 119 | Error: |
| 120 | ! Names must be unique. |
| 121 | x These names are duplicated: |
| 122 | * "b" at locations 1 and 2. |
| 123 | Code |
| 124 | # Multiple columns |
| 125 | vars_rename(c("a", "b", "c", "d"), c = a, d = b) |
| 126 | Condition |
| 127 | Error: |
| 128 | ! Names must be unique. |
| 129 | x These names are duplicated: |
| 130 | * "c" at locations 1 and 3. |
| 131 | * "d" at locations 2 and 4. |
| 132 | Code |
| 133 | # Overlapping rename with one duplicate column |
| 134 | vars_rename(c("a", "b", "c"), b = a, c = b) |
| 135 | Condition |
| 136 | Error: |
| 137 | ! Names must be unique. |
| 138 | x These names are duplicated: |
| 139 | * "c" at locations 2 and 3. |
| 140 | |
| 141 | # vars_rename() type-checks arguments |
| 142 | |
| 143 | Code |
| 144 | vars_rename(letters, A = TRUE) |
| 145 | Condition |
| 146 | Error: |
| 147 | ! Can't rename columns with `TRUE`. |
| 148 | x `TRUE` must be numeric or character, not `TRUE`. |
| 149 | Code |
| 150 | vars_rename(letters, A = 1.5) |
| 151 | Condition |
| 152 | Error: |
| 153 | ! Can't rename columns with `1.5`. |
| 154 | x Can't convert from `1.5` <double> to <integer> due to loss of precision. |
| 155 | Code |
| 156 | vars_rename(letters, A = list()) |
| 157 | Condition |
| 158 | Error: |
| 159 | ! Can't rename columns with `list()`. |
| 160 | x `list()` must be numeric or character, not an empty list. |
| 161 |