inbo / camtrapdp

R package to read and manipulate Camera Trap Data Packages (Camtrap DP)
https://inbo.github.io/camtrapdp/
Other
5 stars 0 forks source link

Dealing with the "observationTags" column of observations #120

Open ddachs opened 2 weeks ago

ddachs commented 2 weeks ago

When dealing with custom attributes one has to extract them from the observationTags column. Otherwise the column is useless.

IMO the ideal behaviour of the observations() function would be to split the observationTags n columns, where n beeing the number of unique tags. At least the option would be nice to have e.g. ( observations(x, splitObservationTags = T)

Something like this:

convert_customTags <- function(x) {

observation_tags <-
  separate_wider_delim (
    x %>% filter(!is.na(observationTags)) %>%
      select(observationID, observationTags),
      observationTags,
      names = LETTERS[1:10],
      too_few = "align_start",
      delim = "|",
      cols_remove = T
                                         ) %>%
  pivot_longer(cols = (A:J),
                        names_to = "letter",
                        values_to = "text") %>%
  filter(!is.na(text)) %>%
  select(-letter) %>%
  separate_wider_delim(cols = "text",
                                     delim = ":",
                                     names = c("tag", "value"),
                                     too_few = "align_start") %>%
  pivot_wider(names_from = tag, values_from = value) %>%
  as.data.table()

y <- merge.data.table(observations, observation_tags, on= "observationID", all.x = T)

return(y)
}

Although this has the flaw, that it only works up to 10 custom attributes. Maybe someone has a better idea?

peterdesmet commented 2 weeks ago

That is a good suggestion. The same is true for deploymentTags. Will have to think how to best implement this. Options:

@sannegovaert @PietrH @damianooldoni thoughts?