-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo_browser.R
69 lines (57 loc) · 1.95 KB
/
demo_browser.R
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
rstudioapi::restartSession()
library(targets)
tar_destroy()
# Write the target script.
file.copy("pipelines/browser_starter.R", "_targets.R", overwrite = TRUE)
# Look at the target script.
tar_edit()
# Inspect the pipeline.
tar_visnetwork()
# This pipeline has an error.
tar_make_clustermq(workers = 2)
# Finish anyway! Set `error = "null"` in tar_option_set().
file.copy("pipelines/browser_null.R", "_targets.R", overwrite = TRUE)
tar_edit()
tar_make_clustermq(workers = 2)
tar_read(analysis) # Just get the results that completed.
tar_visnetwork() # The pipeline still has errors and is not up to date.
# Make debugging easier:
# (1) Set 1 rep per batch.
# (2) Just run the `units = 58` scenario.
file.copy("pipelines/browser_rebatch.R", "_targets.R", overwrite = TRUE)
tar_edit()
tar_visnetwork()
# After re-batching, make note of the first target that errors.
tar_make()
tar_errored() # note "analysis_58_b59aa384"
# Set `debug = "analysis_58_b59aa384"`
# and `cue = tar_cue(mode = "never")`
# in tar_option_set().
file.copy("pipelines/browser_debug.R", "_targets.R", overwrite = TRUE)
tar_edit()
# Run the pipeline in the interactive session (disable the callr process).
rstudioapi::restartSession() # Remove detritus from the session.
library(targets)
tar_make(callr_function = NULL) # Drop into an interactive debugger.
# In the interactive debugger, go to where the error happened
# and reproduce it.
debug(analyze_data)
c
gls(
model = outcome ~ factor,
data = data,
correlation = corSymm(form = ~ measurement | unit),
weights = varIdent(form = ~ 1 | measurement)
)
# Figure out why the error happened.
anyNA(data$outcome)
# Confirm the solution works.
keep_units <- unique(data$unit[!is.na(data$outcome)])
filtered_data <- filter(data, unit %in% keep_units)
gls(
model = outcome ~ factor,
data = filtered_data,
correlation = corSymm(form = ~ measurement | unit),
weights = varIdent(form = ~ 1 | measurement)
) %>%
tidy(conf.int = TRUE, conf.level = 0.95)