I’m having trouble extracting detection data for a number of tags from my .motus dataset. For example, I have a CTT powertag whose manufacturing ID is 55524C1E. When I run my code below, I get the message that I programed (no data found for tag: 55524C1E). However, if I search the Motus dashboard for the deployment ID, I see that it was detected at two of our local stations. Motus Animal summary
Why can’t I pull that data? What is a viable workaround?
rm(list=ls()) #wipes R’s brain
library(motus) library(lubridate) library(dplyr) library(RSQLite)
Set the system environment time zone to UTC (to
ensure that you are always working in UTC)
Sys.setenv(TZ = “UTC”)
setwd(“C:/Users/degrootel/Documents/PARC Stopover/Motus project data/”) #default filepath
#srvTimeout(1800) # Set timeout to 1800 seconds (30 minutes)
sql.motus ← tagme(416, new = FALSE, update = FALSE, dir = “./data/”) ## update data, whole database
Getting tags
#DATE.FORMAT ← “%Y-%m-%d” tags.all ← data.frame(read.csv(“fall_22_tags.csv”), header = T) %>% mutate(StartDate = as.POSIXct(StartDate, format = “%m/%d/%Y %H:%M”))
Loop through each row of tags.all
for (i in 1:nrow(tags.all)) { tag ← tags.all[i, 1] species ← tags.all[i, 3]
Filter and collect the data
df_tag ← tbl(sql.motus, “alltags”) %>% filter(mfgID %in% c(tag)) %>% collect()
Skip if no data found for the tag
if (nrow(df_tag) == 0) { message(paste(“No data found for tag:”, tag, “- skipping.”)) next }
Process and filter the data
df_tag ← df_tag %>% as.data.frame() %>% mutate(ts = as_datetime(ts, tz = “UTC”, origin = “1970-01-01”)) %>% filter(runLen > 2)
Define the filename
filename ← paste0(“./data/fall_22/df_”, tag, “_”, species, “_fall22.RDS”)
Save the filtered data
saveRDS(df_tag, filename) message(paste(“Saved data for tag:”, tag, “to”, filename)) }