Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitfa1403c

Browse files
authored
Don't use a restart to handle stop_on_error = 2L (#232)
In this case, the handler could simply return NULL
1 parenta6f4850 commitfa1403c

24 files changed

+324
-7
lines changed

‎DESCRIPTION‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,14 @@ BugReports: https://github.com/r-lib/evaluate/issues
2525
Depends:
2626
R (>= 3.6.0)
2727
Suggests:
28+
callr,
2829
covr,
2930
ggplot2 (>= 3.3.6),
3031
lattice,
3132
methods,
33+
pkgload,
3234
rlang,
35+
knitr,
3336
testthat (>= 3.0.0),
3437
withr
3538
Config/Needs/website: tidyverse/tidytemplate

‎R/conditions.R‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ condition_handlers <- function(watcher, on_error, on_warning, on_message) {
3434
switch(on_error,
3535
continue= invokeRestart("eval_continue"),
3636
stop= invokeRestart("eval_stop"),
37-
error= invokeRestart("eval_error",cnd)
37+
# No need to invoke a restart as we want the error to be thrown in this case.
38+
error=NULL
3839
)
3940
}
4041
)

‎R/evaluate.R‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,11 @@ evaluate <- function(input,
121121
}
122122
local_inject_funs(envir)
123123

124+
if (is.null(getOption("rlang_trace_top_env"))) {
125+
# If not already set, indicate the top environment to trim traceback
126+
options(rlang_trace_top_env=envir)
127+
}
128+
124129
# Handlers for warnings, errors and messages
125130
user_handlers<-output_handler$calling_handlers
126131
evaluate_handlers<- condition_handlers(
@@ -151,8 +156,7 @@ evaluate <- function(input,
151156
handlers
152157
),
153158
eval_continue=function()TRUE,
154-
eval_stop=function()FALSE,
155-
eval_error=function(cnd) {signalCondition(cnd); stop(cnd)}
159+
eval_stop=function()FALSE
156160
)
157161
watcher$check_devices()
158162

‎tests/testthat/_snaps/conditions.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
Warning in `f()`:
77
Hi!
88

9-
#all threestarts of stop_on_error work as expected
9+
#all threevalues of stop_on_error work as expected
1010

1111
Code
12-
evaluate("stop(\"1\")\n2", stop_on_error = 2L)
12+
ev <-evaluate("stop(\"1\")\n2", stop_on_error = 2L)
1313
Condition
1414
Error:
1515
! 1
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Error in `h()`:
2+
! !
3+
Backtrace:
4+
x
5+
1. \-global f()
6+
2. \-global g()
7+
3. \-global h()
8+
4. \-rlang::abort("!")
9+
Execution halted
10+
Ran 8/8 deferred expressions
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
---
2+
title:document with error
3+
---
4+
5+
6+
```r
7+
f<-function() g()
8+
g<-function() h()
9+
h<-function()rlang::abort("!")
10+
f()
11+
```
12+
13+
```
14+
## Error in `h()`:
15+
## ! !
16+
## Backtrace:
17+
## x
18+
## 1. \-evaluate (local) f()
19+
## 2. \-evaluate (local) g()
20+
## 3. \-evaluate (local) h()
21+
## 4. \-rlang::abort("!")
22+
```
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
3+
processing file: ressources/with-abort-error.Rmd
4+
Error in `h()`:
5+
! !
6+
Backtrace:
7+
1. global f()
8+
2. global g()
9+
3. global h()
10+
11+
Quitting from lines 6-10 [unnamed-chunk-1] (ressources/with-abort-error.Rmd)
12+
Execution halted
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
3+
processing file: ressources/with-stop-error-auto-entrace.Rmd
4+
Error in `h()`:
5+
! !
6+
Backtrace:
7+
1. global f()
8+
2. global g()
9+
3. global h()
10+
11+
Quitting from lines 6-10 [unnamed-chunk-1] (ressources/with-stop-error-auto-entrace.Rmd)
12+
Execution halted
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
---
2+
title:document with error
3+
---
4+
5+
6+
```r
7+
rlang::global_entrace()
8+
options(rlang_backtrace_on_error_report="full")
9+
```
10+
11+
12+
```r
13+
f<-function() g()
14+
g<-function() h()
15+
h<-function() stop("!")
16+
f()
17+
```
18+
19+
```
20+
## Error in `h()`:
21+
## ! !
22+
## Backtrace:
23+
## x
24+
## 1. \-evaluate (local) f()
25+
## 2. \-evaluate (local) g()
26+
## 3. \-evaluate (local) h()
27+
```
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
title:document with error
3+
---
4+
5+
6+
```r
7+
f<-function() g()
8+
g<-function() h()
9+
h<-function() stop("!")
10+
f()
11+
```
12+
13+
```
14+
## Error in h(): !
15+
```

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp