-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrun.R
executable file
·122 lines (106 loc) · 4.2 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
111
112
113
114
115
116
117
118
119
120
121
122
#!/usr/bin/env Rscript
library("optparse")
option_list <- list(
make_option(c("-d", "--dataset"),
type = "character", default = "https://zenodo.org/record/4634013/files/physionet.zip?download=1",
help = "dataset url", metavar = "character"
),
make_option(c("-r", "--run"),
type = "logical", default = TRUE,
help = "run target pipeline [default= %default]", metavar = "logical"
)
)
opt_parser <- OptionParser(option_list = option_list)
opt <- parse_args(opt_parser)
if (is.null(opt$dataset)) {
print_help(opt_parser)
stop("At least one argument must be supplied (dataset).n", call. = FALSE)
}
# pull data from the internet
if (!dir.exists(here::here("inst/extdata/physionet"))) {
dir.create(here::here("inst/extdata"), recursive = TRUE, showWarnings = FALSE)
options(timeout = max(300, getOption("timeout")))
download.file(opt$dataset, method = "libcurl", destfile = here::here("inst/extdata/data.zip"))
# if less than this, probably download error
if (file.size(here::here("inst/extdata/data.zip")) < 300000000) {
stop("Error downloading the dataset, the file seems too small. Please check what happened.")
}
unzip(here::here("inst/extdata/data.zip"), exdir = here::here("inst/extdata"), setTimes = TRUE, overwrite = FALSE)
file.remove(here::here("inst/extdata/data.zip"))
}
if (dir.exists(here::here("inst/extdata"))) {
if (isTRUE(as.logical(Sys.getenv("CI")))) {
Rcpp::compileAttributes()
renv::install(".")
targets::tar_prune()
} else {
tryCatch(
{
pkg_date <- packageDate("false.alarm")
files_r <- paste0(here::here("R"), "/", list.files(here::here("R"), pattern = "*.R"))
files_cpp <- paste0(here::here("R"), "/", list.files(here::here("src"), pattern = "*.cpp"))
files_h <- paste0(here::here("R"), "/", list.files(here::here("src"), pattern = "*.h"))
files <- c(files_r, files_cpp, files_h)
changed <- na.omit(files[as.Date(file.mtime(files)) > (pkg_date)])
if (length(changed) > 0) {
message("false.alarm is outdated, trying to automatically resolve this.")
Rcpp::compileAttributes()
renv::install(".")
}
rm("pkg_date", "files_r", "files_cpp", "files_h", "files", "changed")
},
error = function(e) {
message("false.alarm is not installed, trying to automatically resolve this.")
Rcpp::compileAttributes()
renv::install(".")
},
finally = {
message("done.")
}
)
}
if (opt$run) {
# run targets?
targets::tar_watch(
targets_only = TRUE, supervise = TRUE, seconds = 30, display = "graph", browse = TRUE, outdated = FALSE,
label = c("time", "branches", "size"), port = 55444
)
Sys.setenv(TAR_WARN = "false")
# Uncomment to run targets sequentially on your local machine.
# targets::tar_make()
# Uncomment to run targets in parallel
targets::tar_make_future(workers = 4L)
# on local processes or a Sun Grid Engine cluster.
# targets::tar_make_clustermq(workers = 2L)
# Finally create the output files what will be used on this current Workflowr release:
tryCatch(
{
message("Creating the outputs for Workflowr.")
network <- targets::tar_visnetwork(TRUE, label = c("time", "size", "branches"))
tips <- stringr::str_split_fixed(network$x$nodes$label, pattern = "\n", n = 2)[, 2]
tips <- stringr::str_replace_all(tips, "\n", "<br />")
network$x$nodes$title <- tips
network$x$nodes$label <- network$x$nodes$name
network$x$options$nodes$physics <- TRUE
saveRDS(network, file = here::here("output/network.rds"))
rm(network)
rm(tips)
source(here::here("scripts/helpers/create_output.R"), encoding = "UTF-8")
create_output(file = here::here("output/work_output.rds"), "regime_optimize")
rm(create_output)
},
error = function(e) {
message("Could not create the outputs for Workflowr.")
},
finally = {
message("done.")
}
)
}
} else {
stop("Error installing dataset.")
}
# remove data before commit results
# if (dir.exists(here::here("inst/extdata"))) {
# unlink(here::here("inst/extdata"), recursive = TRUE, force = TRUE)
# }