Skip to content

Commit ab22a26

Browse files
refactor: rename submissions to legacy
1 parent 11ecfdf commit ab22a26

4 files changed

Lines changed: 187 additions & 124 deletions

File tree

r/R/pacm.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ targets_pacm <- list(
165165
bind_rows(
166166
makara = enframe(makara_pacm),
167167
towed = enframe(towed_pacm),
168-
submissions = enframe(subs_pacm),
168+
legacy = enframe(legacy_pacm),
169169
.id = "dataset"
170170
) |>
171171
pivot_wider()

r/R/submissions.R

Lines changed: 73 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
source("packages.R")
22

3-
subs_manifest <- read_csv("data-raw/submissions/submissions.csv", show_col_types = FALSE)
3+
legacy_manifest <- read_csv("data-raw/legacy/submissions.csv", show_col_types = FALSE)
44

55
# functions --------------------------------------------------------------
66

77
# IMPORTANT: changes in source files in `{submission_id}/clean/` are not tracked
8-
# so clean scripts must be re-run manually and then `make_submissions()` must be called to re-load the cleaned data
8+
# so clean scripts must be re-run manually and then `make_legacy()` must be called to re-load the cleaned data
99

1010
# re-load all submissions
11-
# make_submissions(subs_manifest$submission_id)
12-
make_submissions <- function (ids = NULL) {
11+
# make_legacy(legacy_manifest$submission_id)
12+
make_legacy <- function (ids = NULL) {
1313
if (is.null(ids)) {
1414
tar_invalidate(starts_with("sub_"))
1515
} else {
1616
tar_invalidate(any_of(paste0("sub_", ids)))
1717
}
1818

19-
tar_make(subs)
19+
tar_make(legacy)
2020
}
2121

2222
# run the `clean.R` script for a given submission ID
23-
clean_submission <- function (submission_id, root_dir = "data-raw/submissions") {
23+
clean_legacy <- function (submission_id, root_dir = "data-raw/legacy") {
2424
sub_dir <- file.path(root_dir, submission_id)
2525
clean_script <- file.path(sub_dir, "clean.R")
2626
stopifnot(file.exists(clean_script))
@@ -33,44 +33,45 @@ clean_submission <- function (submission_id, root_dir = "data-raw/submissions")
3333
}
3434

3535
# clean multiple submissions
36-
# clean_submissions(subs_manifest$submission_id)
37-
clean_submissions <- function (ids) {
38-
walk(ids, clean_submission)
36+
# clean_legacies(legacy_manifest$submission_id)
37+
clean_legacies <- function (ids) {
38+
walk(ids, clean_legacy)
3939
}
4040

4141
# targets ----------------------------------------------------------------
4242

43-
subs_targets <- tar_map(
44-
values = list(sub_id = subs_manifest$submission_id, sub_format = subs_manifest$format, sub_skip = subs_manifest$skip),
43+
legacy_targets <- tar_map(
44+
values = list(sub_id = legacy_manifest$submission_id, sub_format = legacy_manifest$format, sub_skip = legacy_manifest$skip),
4545
names = c(sub_id),
46-
tar_target(sub, load_submission(sub_id, sub_format, sub_skip, subs_dir, makara_codes), cue = tar_cue(mode = "never"))
46+
tar_target(legacy, load_submission(sub_id, sub_format, sub_skip, legacy_dir, makara_codes), cue = tar_cue(mode = "never"))
4747
)
4848

49-
targets_subs <- list(
50-
tar_target(subs_dir, "data-raw/submissions"),
51-
subs_targets,
49+
# legacy submissions in PACM/Makara formats
50+
targets_legacy <- list(
51+
tar_target(legacy_dir, "data-raw/legacy"),
52+
legacy_targets,
5253
tar_combine(
53-
subs,
54-
subs_targets,
54+
legacy,
55+
legacy_targets,
5556
command = bind_rows(!!!.x)
5657
),
5758

58-
tar_target(subs_metadata_errors, {
59-
subs |>
59+
tar_target(legacy_metadata_errors, {
60+
legacy |>
6061
select(id, metadata) |>
6162
unnest(metadata) |>
6263
select(id, errors) |>
6364
unnest(errors)
6465
}),
65-
tar_target(subs_detectiondata_errors, {
66-
subs |>
66+
tar_target(legacy_detectiondata_errors, {
67+
legacy |>
6768
select(id, detectiondata) |>
6869
unnest(detectiondata) |>
6970
select(id, errors) |>
7071
unnest(errors)
7172
}),
72-
tar_target(subs_gpsdata_errors, {
73-
gpsdata <- subs |>
73+
tar_target(legacy_gpsdata_errors, {
74+
gpsdata <- legacy |>
7475
select(id, gpsdata) |>
7576
unnest(gpsdata)
7677

@@ -81,8 +82,8 @@ targets_subs <- list(
8182
unnest(errors)
8283
}),
8384

84-
tar_target(subs_metadata, {
85-
x <- subs |>
85+
tar_target(legacy_metadata, {
86+
x <- legacy |>
8687
select(id, metadata) |>
8788
unnest(metadata) |>
8889
select(submission_id = id, parsed) |>
@@ -100,8 +101,8 @@ targets_subs <- list(
100101

101102
x
102103
}),
103-
tar_target(subs_detectiondata, {
104-
x <- subs |>
104+
tar_target(legacy_detectiondata, {
105+
x <- legacy |>
105106
select(id, detectiondata) |>
106107
unnest(detectiondata) |>
107108
select(submission_id = id, parsed) |>
@@ -111,14 +112,14 @@ targets_subs <- list(
111112
x |>
112113
distinct(submission_id, UNIQUE_ID) |>
113114
anti_join(
114-
subs_metadata,
115+
legacy_metadata,
115116
by = c("UNIQUE_ID")
116117
)
117118

118119
x
119120
}),
120-
tar_target(subs_gpsdata, {
121-
x <- subs |>
121+
tar_target(legacy_gpsdata, {
122+
x <- legacy |>
122123
select(id, gpsdata) |>
123124
unnest(gpsdata) |>
124125
select(submission_id = id, parsed) |>
@@ -128,16 +129,16 @@ targets_subs <- list(
128129
x_missing <- x |>
129130
distinct(submission_id, UNIQUE_ID) |>
130131
anti_join(
131-
subs_metadata,
132+
legacy_metadata,
132133
by = c("UNIQUE_ID")
133134
)
134135
stopifnot(nrow(x_missing) == 0)
135136

136137
x
137138
}),
138139

139-
tar_target(subs_deployments, {
140-
x <- subs_metadata |>
140+
tar_target(legacy_deployments, {
141+
x <- legacy_metadata |>
141142
clean_names() |>
142143
left_join(
143144
platform_types |>
@@ -182,16 +183,16 @@ targets_subs <- list(
182183

183184
x
184185
}),
185-
tar_target(subs_deployments_map, {
186-
subs_deployments |>
186+
tar_target(legacy_deployments_map, {
187+
legacy_deployments |>
187188
filter(deployment_type == "STATIONARY") |>
188189
st_as_sf(coords = c("longitude", "latitude"), crs = 4326, remove = FALSE) |>
189190
mapview::mapview(zcol = "organization_code", layer.name = "deployments")
190191
}),
191-
tar_target(subs_deployments_pacm, {
192-
subs_deployments |>
192+
tar_target(legacy_deployments_pacm, {
193+
legacy_deployments |>
193194
left_join(
194-
subs_sites |>
195+
legacy_sites |>
195196
st_drop_geometry() |>
196197
unnest(deployments) |>
197198
select(site_id, deployment_id),
@@ -204,8 +205,8 @@ targets_subs <- list(
204205
select(all_of(pacm_names$deployments))
205206
}),
206207

207-
tar_target(subs_sites, {
208-
subs_deployments |>
208+
tar_target(legacy_sites, {
209+
legacy_deployments |>
209210
filter(deployment_type == "STATIONARY") |>
210211
select(organization_code, site, deployment_id, latitude, longitude, monitoring_start_datetime, monitoring_end_datetime) |>
211212
arrange(organization_code, site, monitoring_start_datetime) |>
@@ -248,20 +249,20 @@ targets_subs <- list(
248249
ungroup() |>
249250
select(-n_versions)
250251
}),
251-
tar_target(subs_sites_map, {
252-
subs_sites |>
252+
tar_target(legacy_sites_map, {
253+
legacy_sites |>
253254
select(-deployments) |>
254255
st_as_sf(coords = c("site_longitude", "site_latitude"), crs = 4326) |>
255256
mapview::mapview(label = "site_id", zcol = "n_deployments", layer.name = "# deployments")
256257
}),
257-
tar_target(subs_sites_pacm, {
258-
subs_sites |>
258+
tar_target(legacy_sites_pacm, {
259+
legacy_sites |>
259260
rename(deployment_organization_code = organization_code) |>
260261
select(all_of(pacm_names$sites))
261262
}),
262263

263-
tar_target(subs_analyses, {
264-
x <- subs_detectiondata |>
264+
tar_target(legacy_analyses, {
265+
x <- legacy_detectiondata |>
265266
janitor::clean_names() |>
266267
rename(
267268
qc_data = qc_processing,
@@ -289,7 +290,7 @@ targets_subs <- list(
289290
call_type = map_chr(detections, ~ str_c(na.omit(unique(.$call_type)), collapse = ","))
290291
) |>
291292
left_join(
292-
subs_deployments |>
293+
legacy_deployments |>
293294
select(
294295
organization_code, deployment_id, deployment_code,
295296
recorder_depth_meters, instrument_type, sampling_rate_hz, water_depth_meters,
@@ -335,8 +336,8 @@ targets_subs <- list(
335336

336337
x
337338
}),
338-
tar_target(subs_analyses_pacm, {
339-
subs_analyses |>
339+
tar_target(legacy_analyses_pacm, {
340+
legacy_analyses |>
340341
mutate(
341342
analysis_organization_code = organization_code,
342343
deployment_organization_code = organization_code,
@@ -348,8 +349,8 @@ targets_subs <- list(
348349
select(all_of(pacm_names$analyses))
349350
}),
350351

351-
tar_target(subs_tracks, {
352-
track_positions <- subs_gpsdata |>
352+
tar_target(legacy_tracks, {
353+
track_positions <- legacy_gpsdata |>
353354
clean_names() |>
354355
select(-submission_id) |>
355356
rename(deployment_code = unique_id) |>
@@ -386,7 +387,7 @@ targets_subs <- list(
386387

387388
tracks <- track_positions_hourly_sf |>
388389
left_join(
389-
subs_deployments |>
390+
legacy_deployments |>
390391
select(organization_code, deployment_id, deployment_code),
391392
by = c("deployment_code")
392393
) |>
@@ -400,35 +401,35 @@ targets_subs <- list(
400401

401402
tracks
402403
}),
403-
tar_target(subs_tracks_pacm, {
404-
subs_tracks |>
404+
tar_target(legacy_tracks_pacm, {
405+
legacy_tracks |>
405406
rename(deployment_organization_code = organization_code) |>
406407
select(all_of(pacm_names$tracks))
407408
}),
408409

409-
tar_target(subs_pacm, {
410+
tar_target(legacy_pacm, {
410411
stopifnot(
411-
nrow(subs_metadata_errors) == 0,
412-
nrow(subs_detectiondata_errors) == 0,
413-
nrow(subs_gpsdata_errors) == 0,
414-
all(!is.na(subs_deployments_pacm$organization_code)),
415-
all(na.omit(subs_deployments_pacm$site_id) %in% subs_sites_pacm$site_id),
416-
all(subs_analyses_pacm$deployment_id %in% subs_deployments_pacm$deployment_id),
417-
all(subs_tracks_pacm$deployment_id %in% subs_deployments_pacm$deployment_id),
418-
!anyDuplicated(subs_sites_pacm$site_id),
419-
!anyDuplicated(subs_deployments_pacm$deployment_id),
420-
!anyDuplicated(subs_analyses_pacm$analysis_id),
421-
!anyDuplicated(subs_tracks_pacm$track_id)
412+
nrow(legacy_metadata_errors) == 0,
413+
nrow(legacy_detectiondata_errors) == 0,
414+
nrow(legacy_gpsdata_errors) == 0,
415+
all(!is.na(legacy_deployments_pacm$organization_code)),
416+
all(na.omit(legacy_deployments_pacm$site_id) %in% legacy_sites_pacm$site_id),
417+
all(legacy_analyses_pacm$deployment_id %in% legacy_deployments_pacm$deployment_id),
418+
all(legacy_tracks_pacm$deployment_id %in% legacy_deployments_pacm$deployment_id),
419+
!anyDuplicated(legacy_sites_pacm$site_id),
420+
!anyDuplicated(legacy_deployments_pacm$deployment_id),
421+
!anyDuplicated(legacy_analyses_pacm$analysis_id),
422+
!anyDuplicated(legacy_tracks_pacm$track_id)
422423
)
423424
list(
424-
sites = subs_sites_pacm,
425-
deployments = subs_deployments_pacm,
426-
analyses = subs_analyses_pacm,
427-
tracks = subs_tracks_pacm
425+
sites = legacy_sites_pacm,
426+
deployments = legacy_deployments_pacm,
427+
analyses = legacy_analyses_pacm,
428+
tracks = legacy_tracks_pacm
428429
)
429430
}),
430-
tar_target(subs_pocs, {
431-
subs_metadata |>
431+
tar_target(legacy_pocs, {
432+
legacy_metadata |>
432433
select(submission_id, starts_with("DATA_POC")) |>
433434
distinct() |>
434435
group_by(DATA_POC_NAME, DATA_POC_EMAIL, DATA_POC_AFFILIATION) |>

r/_targets.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ list(
2828
targets_towed,
2929

3030
targets_makara,
31-
targets_subs,
31+
targets_legacy,
3232

3333
targets_pacm
3434
)

0 commit comments

Comments
 (0)