Skip to contents

Nests attachment columns obtained when reading structured data from the kobo landings survey

Usage

pt_nest_attachments(x)

Arguments

x

A data frame containing raw landings data from the Timor operations.

Value

Landings data in which the information about multiple attachments has been nested into a single column (_attachments) this column contains a tibble for every row. This, attachment tibble has as many rows as there are attachments.

Details

One of the disadvantages of using structured survey data is that the tables can become very wide (many columns). This happens when question groups or other fields can be recorded multiple times. For example in the landings survey, for each species captured, about 17 questions are recorded. There is no limit to the number of species that can be recorded in the trip. If, for example a survey records seven species we will have over a hundred columns in the data corresponding to species information.

To improve that situation an avoid using multiple tables we use nested data frames (see tidyr::nest). In nested data frames columns can be lists and can contain arbitrary information, like other data frames, lists, vectors, or models.

Examples

dummy_landings <- tidyr::tibble(
  `_id` = "123",
  `_attachments.0.download_url` = "http://url-1.com",
  `_attachments.0.id` = "01",
  `_attachments.1.download_url` = "http://url-2.com",
  `_attachments.1.id` = "02",
  `_attachments.2.download_url` = NA,
  `_attachments.2.id` = NA
)
pt_nest_attachments(dummy_landings)
#> # A tibble: 1 × 2
#>   `_id` `_attachments`  
#>   <chr> <list>          
#> 1 123   <tibble [2 × 2]>