unlisting trackdata table
Hi @bartk, one of the apps on MoveApps mt_stacks tracks together, which than occasionally have than the track data table of lists. Another App, converts a move2 object into a csv for people to download. The way it is coded currently, it of course gives an error with the track data list table. Not long ago you gave me a piece of code to deal with this, but I'm getting an error that I do not know how to exactly solve.
library(move2)
library(dplyr)
dt <- readRDS("~/Downloads/problemdata.rds")
mt_track_data(dt)
#> # A tibble: 97 × 49
#> individual_name_deplo…¹ deployment_id tag_id individual_id animal_life_stage
#> <chr> <list> <list> <list> <list>
#> 1 CRCH2001..deploy_id.31… <int64 [1]> <int64> <int64 [1]> <fct [1]>
#> 2 CRCH2001..deploy_id.31… <int64 [1]> <int64> <int64 [1]> <fct [1]>
#> 3 CRCH2001..deploy_id.31… <int64 [1]> <int64> <int64 [1]> <fct [1]>
#> 4 CRCH2002..deploy_id.28… <int64 [1]> <int64> <int64 [1]> <fct [1]>
#> 5 CRCH2003..deploy_id.28… <int64 [1]> <int64> <int64 [1]> <fct [1]>
#> 6 CRCH2004..deploy_id.31… <int64 [1]> <int64> <int64 [1]> <fct [1]>
#> 7 CRCH2004..deploy_id.31… <int64 [1]> <int64> <int64 [1]> <fct [1]>
#> 8 CRCH2004..deploy_id.31… <int64 [1]> <int64> <int64 [1]> <fct [1]>
#> 9 CRCH2005..deploy_id.28… <int64 [1]> <int64> <int64 [1]> <fct [1]>
#> 10 CRCH2005..deploy_id.28… <int64 [1]> <int64> <int64 [1]> <fct [1]>
#> # ℹ 87 more rows
#> # ℹ abbreviated name: ¹individual_name_deployment_id_year
#> # ℹ 44 more variables: attachment_type <list>, deploy_off_timestamp <list>,
#> # deploy_on_timestamp <list>, deployment_end_type <list>, duty_cycle <list>,
#> # study_site <list>, tag_readout_method <list>, sensor_type_ids <list>,
#> # capture_location <list>, deploy_on_location <list>,
#> # deploy_off_location <list>, sex <list>, taxon_canonical_name <list>, …
dt |> mutate_track_data(across(where( ~is.list(.x) && all(purrr::map_lgl(.x, \(y) 1==length(unique(y)) ))), ~unlist(purrr::map(.x, unique))))
#> Error in `mutate()`:
#> ℹ In argument: `across(...)`.
#> Caused by error in `across()`:
#> ! Can't compute column `capture_location`.
#> Caused by error in `dplyr_internal_error()`:
You also said to better use vctrs than unlist, but I also cannot get that one working. As these data are not public, I'll share the dataset with you over minerva. Thanks!!
Created on 2024-04-26 with reprex v2.1.0