-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathclean_data_files.R
More file actions
31 lines (27 loc) · 1.04 KB
/
clean_data_files.R
File metadata and controls
31 lines (27 loc) · 1.04 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
#' This file serves two purposes. Both of those concern the data files (i.e.,
#' all non-info files). First, it resaves all data files with strong
#' compression, reducing the overall size of the data. Second, it removes data
#' attributes from all 'multiverseMPT' objects. This ensures that the data used
#' for fitting is not accidentally saved on github.
library("MPTmultiverse")
all_files <- list.files("data/", pattern = ".RData",
full.names = TRUE, recursive = TRUE)
all_files <- all_files[!stringr::str_detect(all_files, "_info\\.RData$")]
for (i in seq_along(all_files)) {
#resave <- FALSE
objs <- load(all_files[i])
for (j in seq_along(objs)) {
#str(get(objs[1]), 1)
#dplyr::glimpse(get(objs[1]))
if (inherits(get(objs[j]), "multiverseMPT") &&
"data" %in% names(attributes(get(objs[j])))) {
#browser()
#resave <- TRUE
tmp <- get(objs[j])
attr(tmp, "data") <- NULL
assign(objs[j], tmp)
}
}
save(list = objs, file = all_files[i], compress = "xz")
rm(list = objs)
}