Skip to content

Commit ac63abf

Browse files
committed
Simplify backtraces of warnings
1 parent e5ee5be commit ac63abf

File tree

2 files changed

+66
-208
lines changed

2 files changed

+66
-208
lines changed

R/mutate.R

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -267,9 +267,7 @@ mutate_cols <- function(.data, dots, error_call = caller_env()) {
267267
warning = function(w) {
268268
# Don't entrace more than 5 warnings because this is very costly
269269
if (is_null(w$trace) && length(warnings) < 5) {
270-
# The frame skipping assumes a regular `base::warning()` stack.
271-
# Also works with warnings emitted from C with `Rf_warning()`.
272-
w$trace <- trace_back(bottom = sys.frame(-5))
270+
w$trace <- trace_back(bottom = error_call)
273271
}
274272
new <- cnd_data(
275273
cnd = w,

tests/testthat/_snaps/conditions.md

Lines changed: 65 additions & 205 deletions
Original file line numberDiff line numberDiff line change
@@ -248,17 +248,9 @@
248248
! msg
249249
---
250250
Backtrace:
251-
x
252-
1. +-dplyr::mutate(df, x = f())
253-
2. +-dplyr:::mutate.data.frame(df, x = f())
254-
3. | \-dplyr:::mutate_cols(.data, dplyr_quosures(...))
255-
4. | +-base::withCallingHandlers(...)
256-
5. | \-(function() {...
257-
6. | \-dplyr:::mutate_col(dots[[i]], .data, mask, new_columns)
258-
7. | \-mask$eval_all_mutate(quo)
259-
8. | \-dplyr (local) eval()
260-
9. \-dplyr (local) f()
261-
10. \-base::warning("msg")
251+
x
252+
1. +-dplyr::mutate(df, x = f())
253+
2. \-dplyr:::mutate.data.frame(df, x = f())
262254
263255

264256
---
@@ -285,17 +277,9 @@
285277
! msg
286278
---
287279
Backtrace:
288-
x
289-
1. +-dplyr::mutate(group_by(df, id), x = f())
290-
2. +-dplyr:::mutate.data.frame(group_by(df, id), x = f())
291-
3. | \-dplyr:::mutate_cols(.data, dplyr_quosures(...))
292-
4. | +-base::withCallingHandlers(...)
293-
5. | \-(function() {...
294-
6. | \-dplyr:::mutate_col(dots[[i]], .data, mask, new_columns)
295-
7. | \-mask$eval_all_mutate(quo)
296-
8. | \-dplyr (local) eval()
297-
9. \-dplyr (local) f()
298-
10. \-base::warning("msg")
280+
x
281+
1. +-dplyr::mutate(group_by(df, id), x = f())
282+
2. \-dplyr:::mutate.data.frame(group_by(df, id), x = f())
299283
300284
[[2]]
301285
<warning/rlang_warning>
@@ -305,17 +289,9 @@
305289
! msg
306290
---
307291
Backtrace:
308-
x
309-
1. +-dplyr::mutate(group_by(df, id), x = f())
310-
2. +-dplyr:::mutate.data.frame(group_by(df, id), x = f())
311-
3. | \-dplyr:::mutate_cols(.data, dplyr_quosures(...))
312-
4. | +-base::withCallingHandlers(...)
313-
5. | \-(function() {...
314-
6. | \-dplyr:::mutate_col(dots[[i]], .data, mask, new_columns)
315-
7. | \-mask$eval_all_mutate(quo)
316-
8. | \-dplyr (local) eval()
317-
9. \-dplyr (local) f()
318-
10. \-base::warning("msg")
292+
x
293+
1. +-dplyr::mutate(group_by(df, id), x = f())
294+
2. \-dplyr:::mutate.data.frame(group_by(df, id), x = f())
319295
320296

321297
---
@@ -342,17 +318,9 @@
342318
! msg
343319
---
344320
Backtrace:
345-
x
346-
1. +-dplyr::mutate(rowwise(df), x = f())
347-
2. +-dplyr:::mutate.data.frame(rowwise(df), x = f())
348-
3. | \-dplyr:::mutate_cols(.data, dplyr_quosures(...))
349-
4. | +-base::withCallingHandlers(...)
350-
5. | \-(function() {...
351-
6. | \-dplyr:::mutate_col(dots[[i]], .data, mask, new_columns)
352-
7. | \-mask$eval_all_mutate(quo)
353-
8. | \-dplyr (local) eval()
354-
9. \-dplyr (local) f()
355-
10. \-base::warning("msg")
321+
x
322+
1. +-dplyr::mutate(rowwise(df), x = f())
323+
2. \-dplyr:::mutate.data.frame(rowwise(df), x = f())
356324
357325
[[2]]
358326
<warning/rlang_warning>
@@ -362,17 +330,9 @@
362330
! msg
363331
---
364332
Backtrace:
365-
x
366-
1. +-dplyr::mutate(rowwise(df), x = f())
367-
2. +-dplyr:::mutate.data.frame(rowwise(df), x = f())
368-
3. | \-dplyr:::mutate_cols(.data, dplyr_quosures(...))
369-
4. | +-base::withCallingHandlers(...)
370-
5. | \-(function() {...
371-
6. | \-dplyr:::mutate_col(dots[[i]], .data, mask, new_columns)
372-
7. | \-mask$eval_all_mutate(quo)
373-
8. | \-dplyr (local) eval()
374-
9. \-dplyr (local) f()
375-
10. \-base::warning("msg")
333+
x
334+
1. +-dplyr::mutate(rowwise(df), x = f())
335+
2. \-dplyr:::mutate.data.frame(rowwise(df), x = f())
376336
377337

378338
---
@@ -412,23 +372,13 @@
412372
! msg
413373
---
414374
Backtrace:
415-
x
416-
1. +-dplyr::mutate(...)
417-
2. +-dplyr::group_by(...)
418-
3. +-dplyr::mutate(rowwise(group_by(df, g = f():n())), x = f())
419-
4. +-dplyr::rowwise(group_by(df, g = f():n()))
420-
5. +-dplyr::group_by(df, g = f():n())
421-
6. +-dplyr:::group_by.data.frame(df, g = f():n())
422-
7. | \-dplyr::group_by_prepare(.data, ..., .add = .add, error_call = current_env())
423-
8. | \-dplyr:::add_computed_columns(.data, new_groups, error_call = error_call)
424-
9. | \-dplyr:::mutate_cols(...)
425-
10. | +-base::withCallingHandlers(...)
426-
11. | \-(function() {...
427-
12. | \-dplyr:::mutate_col(dots[[i]], .data, mask, new_columns)
428-
13. | \-mask$eval_all_mutate(quo)
429-
14. | \-dplyr (local) eval()
430-
15. \-dplyr (local) f()
431-
16. \-base::warning("msg")
375+
x
376+
1. +-dplyr::mutate(...)
377+
2. +-dplyr::group_by(...)
378+
3. +-dplyr::mutate(rowwise(group_by(df, g = f():n())), x = f())
379+
4. +-dplyr::rowwise(group_by(df, g = f():n()))
380+
5. +-dplyr::group_by(df, g = f():n())
381+
6. \-dplyr:::group_by.data.frame(df, g = f():n())
432382
433383
[[2]]
434384
<warning/rlang_warning>
@@ -438,19 +388,11 @@
438388
! msg
439389
---
440390
Backtrace:
441-
x
442-
1. +-dplyr::mutate(...)
443-
2. +-dplyr::group_by(...)
444-
3. +-dplyr::mutate(rowwise(group_by(df, g = f():n())), x = f())
445-
4. +-dplyr:::mutate.data.frame(...)
446-
5. | \-dplyr:::mutate_cols(.data, dplyr_quosures(...))
447-
6. | +-base::withCallingHandlers(...)
448-
7. | \-(function() {...
449-
8. | \-dplyr:::mutate_col(dots[[i]], .data, mask, new_columns)
450-
9. | \-mask$eval_all_mutate(quo)
451-
10. | \-dplyr (local) eval()
452-
11. \-dplyr (local) f()
453-
12. \-base::warning("msg")
391+
x
392+
1. +-dplyr::mutate(...)
393+
2. +-dplyr::group_by(...)
394+
3. +-dplyr::mutate(rowwise(group_by(df, g = f():n())), x = f())
395+
4. \-dplyr:::mutate.data.frame(...)
454396
455397
[[3]]
456398
<warning/rlang_warning>
@@ -460,19 +402,11 @@
460402
! msg
461403
---
462404
Backtrace:
463-
x
464-
1. +-dplyr::mutate(...)
465-
2. +-dplyr::group_by(...)
466-
3. +-dplyr::mutate(rowwise(group_by(df, g = f():n())), x = f())
467-
4. +-dplyr:::mutate.data.frame(...)
468-
5. | \-dplyr:::mutate_cols(.data, dplyr_quosures(...))
469-
6. | +-base::withCallingHandlers(...)
470-
7. | \-(function() {...
471-
8. | \-dplyr:::mutate_col(dots[[i]], .data, mask, new_columns)
472-
9. | \-mask$eval_all_mutate(quo)
473-
10. | \-dplyr (local) eval()
474-
11. \-dplyr (local) f()
475-
12. \-base::warning("msg")
405+
x
406+
1. +-dplyr::mutate(...)
407+
2. +-dplyr::group_by(...)
408+
3. +-dplyr::mutate(rowwise(group_by(df, g = f():n())), x = f())
409+
4. \-dplyr:::mutate.data.frame(...)
476410
477411
[[4]]
478412
<warning/rlang_warning>
@@ -482,17 +416,9 @@
482416
! msg
483417
---
484418
Backtrace:
485-
x
486-
1. +-dplyr::mutate(...)
487-
2. +-dplyr:::mutate.data.frame(...)
488-
3. | \-dplyr:::mutate_cols(.data, dplyr_quosures(...))
489-
4. | +-base::withCallingHandlers(...)
490-
5. | \-(function() {...
491-
6. | \-dplyr:::mutate_col(dots[[i]], .data, mask, new_columns)
492-
7. | \-mask$eval_all_mutate(quo)
493-
8. | \-dplyr (local) eval()
494-
9. \-dplyr (local) f()
495-
10. \-base::warning("msg")
419+
x
420+
1. +-dplyr::mutate(...)
421+
2. \-dplyr:::mutate.data.frame(...)
496422
497423
[[5]]
498424
<warning/rlang_warning>
@@ -502,17 +428,9 @@
502428
! msg
503429
---
504430
Backtrace:
505-
x
506-
1. +-dplyr::mutate(...)
507-
2. +-dplyr:::mutate.data.frame(...)
508-
3. | \-dplyr:::mutate_cols(.data, dplyr_quosures(...))
509-
4. | +-base::withCallingHandlers(...)
510-
5. | \-(function() {...
511-
6. | \-dplyr:::mutate_col(dots[[i]], .data, mask, new_columns)
512-
7. | \-mask$eval_all_mutate(quo)
513-
8. | \-dplyr (local) eval()
514-
9. \-dplyr (local) f()
515-
10. \-base::warning("msg")
431+
x
432+
1. +-dplyr::mutate(...)
433+
2. \-dplyr:::mutate.data.frame(...)
516434
517435

518436
---
@@ -546,17 +464,9 @@
546464
! msg
547465
---
548466
Backtrace:
549-
x
550-
1. +-dplyr::mutate(rowwise(df), x = f())
551-
2. +-dplyr:::mutate.data.frame(rowwise(df), x = f())
552-
3. | \-dplyr:::mutate_cols(.data, dplyr_quosures(...))
553-
4. | +-base::withCallingHandlers(...)
554-
5. | \-(function() {...
555-
6. | \-dplyr:::mutate_col(dots[[i]], .data, mask, new_columns)
556-
7. | \-mask$eval_all_mutate(quo)
557-
8. | \-dplyr (local) eval()
558-
9. \-dplyr (local) f()
559-
10. \-base::warning("msg")
467+
x
468+
1. +-dplyr::mutate(rowwise(df), x = f())
469+
2. \-dplyr:::mutate.data.frame(rowwise(df), x = f())
560470
561471
Message
562472
... with 1 more warning.
@@ -597,17 +507,9 @@
597507
! msg
598508
---
599509
Backtrace:
600-
x
601-
1. +-dplyr::mutate(rowwise(df), x = f())
602-
2. +-dplyr:::mutate.data.frame(rowwise(df), x = f())
603-
3. | \-dplyr:::mutate_cols(.data, dplyr_quosures(...))
604-
4. | +-base::withCallingHandlers(...)
605-
5. | \-(function() {...
606-
6. | \-dplyr:::mutate_col(dots[[i]], .data, mask, new_columns)
607-
7. | \-mask$eval_all_mutate(quo)
608-
8. | \-dplyr (local) eval()
609-
9. \-dplyr (local) f()
610-
10. \-base::warning("msg")
510+
x
511+
1. +-dplyr::mutate(rowwise(df), x = f())
512+
2. \-dplyr:::mutate.data.frame(rowwise(df), x = f())
611513
612514
Message
613515
... with 4 more warnings.
@@ -649,24 +551,12 @@
649551
! foo
650552
---
651553
Backtrace:
652-
x
653-
1. +-dplyr (local) foo()
654-
2. | \-dplyr (local) bar()
655-
3. | +-dplyr::mutate(group_by(df, x = f(1):n()), x = f(1, base = FALSE))
656-
4. | +-dplyr::group_by(df, x = f(1):n())
657-
5. | \-dplyr:::group_by.data.frame(df, x = f(1):n())
658-
6. | \-dplyr::group_by_prepare(.data, ..., .add = .add, error_call = current_env())
659-
7. | \-dplyr:::add_computed_columns(.data, new_groups, error_call = error_call)
660-
8. | \-dplyr:::mutate_cols(...)
661-
9. | +-base::withCallingHandlers(...)
662-
10. | \-(function() {...
663-
11. | \-dplyr:::mutate_col(dots[[i]], .data, mask, new_columns)
664-
12. | \-mask$eval_all_mutate(quo)
665-
13. | \-dplyr (local) eval()
666-
14. \-dplyr (local) f(1)
667-
15. \-dplyr (local) g(...)
668-
16. \-dplyr (local) h(...)
669-
17. \-base::warning("foo")
554+
x
555+
1. \-dplyr (local) foo()
556+
2. \-dplyr (local) bar()
557+
3. +-dplyr::mutate(group_by(df, x = f(1):n()), x = f(1, base = FALSE))
558+
4. +-dplyr::group_by(df, x = f(1):n())
559+
5. \-dplyr:::group_by.data.frame(df, x = f(1):n())
670560
671561
[[2]]
672562
<warning/rlang_warning>
@@ -676,21 +566,11 @@
676566
! foo
677567
---
678568
Backtrace:
679-
x
680-
1. +-dplyr (local) foo()
681-
2. | \-dplyr (local) bar()
682-
3. | +-dplyr::mutate(group_by(df, x = f(1):n()), x = f(1, base = FALSE))
683-
4. | \-dplyr:::mutate.data.frame(...)
684-
5. | \-dplyr:::mutate_cols(.data, dplyr_quosures(...))
685-
6. | +-base::withCallingHandlers(...)
686-
7. | \-(function() {...
687-
8. | \-dplyr:::mutate_col(dots[[i]], .data, mask, new_columns)
688-
9. | \-mask$eval_all_mutate(quo)
689-
10. | \-dplyr (local) eval()
690-
11. \-dplyr (local) f(1, base = FALSE)
691-
12. \-dplyr (local) g(...)
692-
13. \-dplyr (local) h(...)
693-
14. \-rlang::warn("foo")
569+
x
570+
1. \-dplyr (local) foo()
571+
2. \-dplyr (local) bar()
572+
3. +-dplyr::mutate(group_by(df, x = f(1):n()), x = f(1, base = FALSE))
573+
4. \-dplyr:::mutate.data.frame(...)
694574
695575
[[3]]
696576
<warning/rlang_warning>
@@ -700,21 +580,11 @@
700580
! foo
701581
---
702582
Backtrace:
703-
x
704-
1. +-dplyr (local) foo()
705-
2. | \-dplyr (local) bar()
706-
3. | +-dplyr::mutate(group_by(df, x = f(1):n()), x = f(1, base = FALSE))
707-
4. | \-dplyr:::mutate.data.frame(...)
708-
5. | \-dplyr:::mutate_cols(.data, dplyr_quosures(...))
709-
6. | +-base::withCallingHandlers(...)
710-
7. | \-(function() {...
711-
8. | \-dplyr:::mutate_col(dots[[i]], .data, mask, new_columns)
712-
9. | \-mask$eval_all_mutate(quo)
713-
10. | \-dplyr (local) eval()
714-
11. \-dplyr (local) f(1, base = FALSE)
715-
12. \-dplyr (local) g(...)
716-
13. \-dplyr (local) h(...)
717-
14. \-rlang::warn("foo")
583+
x
584+
1. \-dplyr (local) foo()
585+
2. \-dplyr (local) bar()
586+
3. +-dplyr::mutate(group_by(df, x = f(1):n()), x = f(1, base = FALSE))
587+
4. \-dplyr:::mutate.data.frame(...)
718588
719589
[[4]]
720590
<warning/rlang_warning>
@@ -724,20 +594,10 @@
724594
! foo
725595
---
726596
Backtrace:
727-
x
728-
1. +-dplyr (local) foo()
729-
2. | \-dplyr (local) bar()
730-
3. | +-dplyr::mutate(group_by(df, x = f(1):n()), x = f(1, base = FALSE))
731-
4. | \-dplyr:::mutate.data.frame(...)
732-
5. | \-dplyr:::mutate_cols(.data, dplyr_quosures(...))
733-
6. | +-base::withCallingHandlers(...)
734-
7. | \-(function() {...
735-
8. | \-dplyr:::mutate_col(dots[[i]], .data, mask, new_columns)
736-
9. | \-mask$eval_all_mutate(quo)
737-
10. | \-dplyr (local) eval()
738-
11. \-dplyr (local) f(1, base = FALSE)
739-
12. \-dplyr (local) g(...)
740-
13. \-dplyr (local) h(...)
741-
14. \-rlang::warn("foo")
597+
x
598+
1. \-dplyr (local) foo()
599+
2. \-dplyr (local) bar()
600+
3. +-dplyr::mutate(group_by(df, x = f(1):n()), x = f(1, base = FALSE))
601+
4. \-dplyr:::mutate.data.frame(...)
742602
743603

0 commit comments

Comments
 (0)