-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.R
110 lines (66 loc) · 3.29 KB
/
run.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# Initial setup -----------------------------------------------------------
# Install necessary libraries for data preparation
if (!require('pak')) utils::install.packages('pak')
pak::pkg_install("gorkang/jsPsychHelpeR")
# Run pipeline -------------------------------------------------------------
# Run data preparation
targets::tar_make()
# The full pipeline is in the file _targets.R. Open it with:
# rstudioapi::navigateToFile("_targets.R")
# Visualize targets tree
targets::tar_visnetwork(targets_only = TRUE, label = "time")
# In case of an error ---
# You can clean up everything so targets will run from scratch
# targets::tar_destroy()
# See: https://books.ropensci.org/targets/debugging.html#workspaces
# tar_workspaces() # Lists the available workspaces (e.g. DF_clean)
# tar_workspace(DF_clean) # Loads the errored workspace
# Check results -----------------------------------------------------------
# After running the pipeline with targets::tar_make()
# Load all libraries
targets::tar_load_globals()
# Load all targets (e.g. DF_joined, DF_analysis, etc.)
targets::tar_load_everything()
# Or load a specific DF
# targets::tar_load(DF_joined)
# List available objects
targets::tar_objects()
# See DF_analysis dataframe
DF_analysis$DF_analysis |> View()
# Join data from DF_joined to DF_analysis ---------------------------------
# Select columns from DF_joined
DF_final = DF_joined |>
select(id,
matches("DEMOGR46"),
ends_with("DIRd"), ends_with("DIRt")
)
# Save to a csv
write_csv(DF_final, "outputs/data/DF_final.csv")
write_csv2(DF_final, "outputs/data/DF_final_sp.csv")
# Edit report ---------------------------------------------------------------
# Open report_analysis.Rmd and adapt the code:
rstudioapi::navigateToFile("Rmd/report_analysis.Rmd")
# After editing it you need to open _targets.R and uncomment the
# Analysis report tar_render() lines there:
rstudioapi::navigateToFile("_targets.R")
# And finally run the full pipeline:
targets::tar_make()
# Other commands ----------------------------------------------------------
# Destroy pipeline
# targets::tar_destroy() # This will force the full pipeline to start from 0
# CHECK warnings
targets::tar_meta() %>% dplyr::select(name, warnings) %>%tidyr::drop_na()
# Create docker container -------------------------------------------------
# system("docker builder prune --all -f") # Clean all docker builder cache
PID = 999
jsPsychHelpeR::create_docker_container(PID = PID)
file.remove(list.files(paste0("~/Downloads/jsPsychHelpeR", PID, "/outputs"), recursive = TRUE, full.names = TRUE))
system(paste0("docker run --rm -d --name pid", PID, " -v ~/Downloads/jsPsychHelpeR", PID, "/outputs:/home/project/jsPsychHelpeR/outputs:rw gorkang/jspsychhelper:pid", PID))
# Admin -------------------------------------------------------------------
# Create new task
jsPsychHelpeR::create_new_task("NEW_TASK", get_info_googledoc = TRUE)
# Get data
jsPsychHelpeR::get_zip(
pid = "protocols_DEV/999/", what = "data", where = "data/",
credentials_file = "~/[email protected]/RESEARCH/PROYECTOS-Code/jsPsychR/jsPsychAdmin/.vault/.credentials"
)