-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo_workspace.R
47 lines (35 loc) · 1.25 KB
/
demo_workspace.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
rstudioapi::restartSession()
library(targets)
tar_destroy()
# Write the target script.
file.copy("pipelines/workspace.R", "_targets.R", overwrite = TRUE)
# Look at the target script and note the workspace_on_error option.
tar_edit()
# Inspect the pipeline.
tar_visnetwork()
# Try to run the pipeline.
tar_make()
# List available workspaces.
tar_workspaces() # "analysis_02de2921"
file.size("_targets/workspaces/analysis_02de2921") # size in bytes (small file)
# Get the traceback from the workspace.
tar_traceback(analysis_02de2921)
# Before loading the workspace:
print(search()) # load packages
print(ls()) # list of objects in the environment
print(digest::digest(.Random.seed)) # state of the random number generator
# Load the workspace
tar_workspace(analysis_02de2921)
# After loading the workspace:
print(search()) # More packages loaded.
print(ls()) # Functions and data are in the environment.
print(digest::digest(.Random.seed)) # The target's seed is set.
# Reproduce the error in the local interactive R session
# outside the pipeline.
analyze_data(data)
# Diagnose the bug.
anyNA(data$outcome)
# Confirm the solution.
keep_units <- unique(data$unit[!is.na(data$outcome)])
filtered_data <- filter(data, unit %in% keep_units)
analyze_data(filtered_data)