Code
source("R/FUNCTIONS.R")This document explains the process of verifying camera IDs between two datasets: the camera trap setup data and the species records data. The goal is to identify any mismatches or inconsistencies in camera IDs between these datasets.
To solve this issue, we follow some of the first basic steps from previous checks, as using our customized read_sheet function that provides the full paths of all .xlsx files available in order to read the species sheet from all files.
source("R/FUNCTIONS.R")We load two datasets from the spreadsheet: 1. Camera trap setup data (ct) 2. Species records data (rec)
# Read camera trap setup data
ct <- read_sheet(path = "Example", sheet = "Camera_trap")
# Read species records data
rec <- read_sheet(path = "Example", sheet = "Species_records_camera")The verification process consists of two main checks:
This check identifies any camera IDs in the species records that don’t exist in the camera trap data:
record_to_ct <- purrr::map2(ct, rec, function(c, r) {
base::setdiff(r$Camera_id, c$Camera_id) |>
tibble::enframe(name = "Error", value = "Camera_id") |>
dplyr::mutate(note = "Record without camera on sheet")
}) |>
purrr::discard(~ nrow(.x) == 0) |>
dplyr::bind_rows(.id = "Dataset")
head(record_to_ct)# A tibble: 0 × 0
This check identifies any camera IDs in the camera trap data that doesn’t have corresponding records. The results from this check is not an error, since the camera could have been installed and resulted in zero records.
ct_to_record <- purrr::map2(ct, rec, function(c, r) {
base::setdiff(c$Camera_id, r$Camera_id) |>
tibble::enframe(name = "Error", value = "Camera_id") |>
dplyr::mutate(note = "Camera without record on sheet")
}) |>
purrr::discard(~ nrow(.x) == 0) |>
dplyr::bind_rows(.id = "Dataset")
head(ct_to_record)# A tibble: 6 × 4
Dataset Error Camera_id note
<chr> <int> <chr> <chr>
1 Example1 1 - Camera without record on sheet
2 Example3 1 CAM000 Camera without record on sheet
3 Example4 1 MX007 Camera without record on sheet
4 Example6 1 C1 Camera without record on sheet
5 Example6 2 C3 Camera without record on sheet
6 Example6 3 C4 Camera without record on sheet
This process performs a data audit by iterating through the lists of records and camera trap data. For each corresponding dataset, an anti_join operation finds rows in the records data that do not have a match in the camera trap data, using Structure_id and Camera_id as the composite key. In other words, the code identifies record entries for a specific structure and camera that are not listed in the corresponding camera trap data.
purrr::map2(rec, ct, function(record, camera) {
record |>
dplyr::anti_join(camera, by = c("Structure_id", "Camera_id")) |>
dttm_update(date_col = "Record_date", time_col = "Record_time") |>
dplyr::select(Structure_id:Record_date)
}) |>
dplyr::bind_rows(.id = "dataset")# A tibble: 1,209 × 5
dataset Structure_id Camera_id Species Record_date
<chr> <chr> <chr> <chr> <dttm>
1 Example1 BC1(galeria) cam1 Procyon cancrivorus NA
2 Example1 BC1(galeria) cam1 Dasypus novemcinctus NA
3 Example1 BC1(galeria) VITA_04 Dasypus sp. 2020-02-24 01:18:00
4 Example1 BC1(galeria) VITA_15 Aramides sp. 2022-06-25 10:25:00
5 Example1 BC1(galeria) VITA_15 Aramides sp. 2022-06-25 14:54:00
6 Example1 BC1(galeria) VITA_15_1 Aramides sp. 2022-07-01 12:03:00
7 Example1 BC1(galeria) VITA_15_1 Mammalia 2022-07-12 05:57:00
8 Example1 BC1(galeria) cam2 Aramides sp. 2022-08-28 13:27:00
9 Example1 BC1(galeria) cam2 Aramides sp. 2022-08-29 10:41:00
10 Example1 BC1(galeria) cam3 Aramides sp. 2022-09-09 13:13:00
# ℹ 1,199 more rows