Debian Codegraph @

tests/testthat/_snaps/eval-select.md

raw symbols SCIP
1 # include and exclude validate their inputs
2
3 Code
4 x <- list(a = 1, b = 2, c = 3)
5 (expect_error(select_loc(x, "a", include = 1)))
6 Output
7 <error/rlang_error>
8 Error in `select_loc()`:
9 ! `include` must be a character vector.
10 Code
11 (expect_error(select_loc(x, "a", include = "d")))
12 Output
13 <error/rlang_error>
14 Error in `select_loc()`:
15 ! `include` must only include variables found in `data`.
16 i Unknown variables: d
17 Code
18 (expect_error(select_loc(x, "a", exclude = 1)))
19 Output
20 <error/rlang_error>
21 Error in `select_loc()`:
22 ! `include` must be a character vector.
23
24 # can forbid rename syntax (#178)
25
26 Code
27 (expect_error(select_loc(mtcars, c(foo = cyl), allow_rename = FALSE)))
28 Output
29 <error/tidyselect:::error_disallowed_rename>
30 Error in `select_loc()`:
31 ! Can't rename variables in this context.
32 Code
33 (expect_error(select_loc(mtcars, c(cyl, foo = cyl), allow_rename = FALSE)))
34 Output
35 <error/tidyselect:::error_disallowed_rename>
36 Error in `select_loc()`:
37 ! Can't rename variables in this context.
38 Code
39 (expect_error(select_loc(mtcars, c(cyl, foo = mpg), allow_rename = FALSE)))
40 Output
41 <error/tidyselect:::error_disallowed_rename>
42 Error in `select_loc()`:
43 ! Can't rename variables in this context.
44 Code
45 (expect_error(select_loc(mtcars, c(foo = mpg, cyl), allow_rename = FALSE)))
46 Output
47 <error/tidyselect:::error_disallowed_rename>
48 Error in `select_loc()`:
49 ! Can't rename variables in this context.
50
51 # can forbid empty selections
52
53 Code
54 select_loc(mtcars, allow_empty = FALSE)
55 Condition
56 Error in `select_loc()`:
57 ! Must select at least one item.
58 Code
59 select_loc(mtcars, integer(), allow_empty = FALSE)
60 Condition
61 Error in `select_loc()`:
62 ! Must select at least one item.
63 Code
64 select_loc(mtcars, starts_with("z"), allow_empty = FALSE)
65 Condition
66 Error in `select_loc()`:
67 ! Must select at least one item.
68
69 # eval_select() errors mention correct calls
70
71 Code
72 (expect_error(select_loc(mtcars, f())))
73 Output
74 <error/rlang_error>
75 Error in `select_loc()`:
76 Caused by error in `f()`:
77 ! foo
78
79 # predicate outputs are type-checked
80
81 Code
82 (expect_error(select_loc(mtcars, function(x) "")))
83 Output
84 <error/rlang_error>
85 Error in `select_loc()`:
86 ! Predicate must return `TRUE` or `FALSE`, not `""`.
87
88 # eval_select() produces correct backtraces
89
90 Code
91 print(expect_error(select_loc(mtcars, f(base = TRUE))))
92 Output
93 <error/rlang_error>
94 Error in `select_loc()`:
95 i In argument: `f(base = TRUE)`.
96 Caused by error in `h()`:
97 ! foo
98 ---
99 Backtrace:
100 x
101 1. +-base::print(expect_error(select_loc(mtcars, f(base = TRUE))))
102 2. +-testthat::expect_error(select_loc(mtcars, f(base = TRUE)))
103 3. | \-testthat:::expect_condition_matching(...)
104 4. | \-testthat:::quasi_capture(...)
105 5. | +-testthat (local) .capture(...)
106 6. | | \-base::withCallingHandlers(...)
107 7. | \-rlang::eval_bare(quo_get_expr(.quo), quo_get_env(.quo))
108 8. +-tidyselect:::select_loc(mtcars, f(base = TRUE))
109 9. | \-tidyselect::eval_select(...)
110 10. | \-tidyselect:::eval_select_impl(...)
111 11. | +-tidyselect:::with_subscript_errors(...)
112 12. | | \-base::withCallingHandlers(...)
113 13. | \-tidyselect:::vars_select_eval(...)
114 14. | \-tidyselect:::walk_data_tree(expr, data_mask, context_mask)
115 15. | \-tidyselect:::eval_context(expr, context_mask, call = error_call)
116 16. | +-tidyselect:::with_chained_errors(...)
117 17. | | \-base::withCallingHandlers(...)
118 18. | \-rlang::eval_tidy(as_quosure(expr, env), context_mask)
119 19. \-tidyselect (local) f(base = TRUE)
120 20. \-tidyselect (local) g(base)
121 21. \-tidyselect (local) h(base)
122 22. \-base::stop("foo")
123 Code
124 print(expect_error(select_loc(mtcars, f(base = FALSE))))
125 Output
126 <error/rlang_error>
127 Error in `select_loc()`:
128 i In argument: `f(base = FALSE)`.
129 Caused by error in `h()`:
130 ! foo
131 ---
132 Backtrace:
133 x
134 1. +-base::print(expect_error(select_loc(mtcars, f(base = FALSE))))
135 2. +-testthat::expect_error(select_loc(mtcars, f(base = FALSE)))
136 3. | \-testthat:::expect_condition_matching(...)
137 4. | \-testthat:::quasi_capture(...)
138 5. | +-testthat (local) .capture(...)
139 6. | | \-base::withCallingHandlers(...)
140 7. | \-rlang::eval_bare(quo_get_expr(.quo), quo_get_env(.quo))
141 8. +-tidyselect:::select_loc(mtcars, f(base = FALSE))
142 9. | \-tidyselect::eval_select(...)
143 10. | \-tidyselect:::eval_select_impl(...)
144 11. | +-tidyselect:::with_subscript_errors(...)
145 12. | | \-base::withCallingHandlers(...)
146 13. | \-tidyselect:::vars_select_eval(...)
147 14. | \-tidyselect:::walk_data_tree(expr, data_mask, context_mask)
148 15. | \-tidyselect:::eval_context(expr, context_mask, call = error_call)
149 16. | +-tidyselect:::with_chained_errors(...)
150 17. | | \-base::withCallingHandlers(...)
151 18. | \-rlang::eval_tidy(as_quosure(expr, env), context_mask)
152 19. \-tidyselect (local) f(base = FALSE)
153 20. \-tidyselect (local) g(base)
154 21. \-tidyselect (local) h(base)
155
156 # eval_select() produces correct chained errors
157
158 Code
159 (expect_error(select_loc(mtcars, 1 + "")))
160 Output
161 <error/rlang_error>
162 Error in `select_loc()`:
163 i In argument: `1 + ""`.
164 Caused by error in `1 + ""`:
165 ! non-numeric argument to binary operator
166 Code
167 f <- (function() 1 + "")
168 (expect_error(select_loc(mtcars, f())))
169 Output
170 <error/rlang_error>
171 Error in `select_loc()`:
172 i In argument: `f()`.
173 Caused by error in `1 + ""`:
174 ! non-numeric argument to binary operator
175