-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsample_script.R
More file actions
80 lines (50 loc) · 1 KB
/
sample_script.R
File metadata and controls
80 lines (50 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# Interactive help ------------------------
f <- function(a) g(a)
g <- function(b) h(b)
h <- function(c) i(c)
i <- function(d) {
if (!is.numeric(d)) {
stop("`d` must be numeric", call. = FALSE)
}
d + 10
}
f("a")
traceback()
library(dplyr)
iris %>% filter(Sepal.Lengt > 4)
traceback()
rlang::last_trace()
rlang::last_error()
# recover ----------------------------------
options(error = recover)
f(12)
f("a")
options(error = NULL)
# Browser and breakpoints ------------------
dput(x=sample(1:30, 24))
dput(1:5)
dput(c(1:5, 6))
source("code/example_breakpoint.R")
dput_range(sample(1:30, 25))
dput_range(c(1:5, 6))
# Now try with browser
# then with breakpoints
dput_range(sample(1:30, 15))
# debug() ---------------------------------
myfun <- function(i) {
while(i<=10) {
print(i*2)
i <- i+1
}
}
myfun(6)
debug(myfun)
myfun(4)
undebug(myfun)
debugonce(myfun)
myfun(2)
# Now pick a function to look into, or try to resolve an error that you had.
# Examples:
sample
lm
ggplot