This function extracts data from a table that are summarised by applying a schema description to it.

getData(schema = NULL, input = NULL)

Arguments

schema

[character(1)]
the (validated) schema description of input.

input

[character(1)]
table to reorganise.

Value

a table where columns and rows are summarised

Examples

input <- tabs2shift$clusters_nested
schema <- setCluster(id = "sublevel",
                     group = "territories", member = c(1, 1, 2),
                     left = 1, top = c(3, 8, 15)) %>%
  setIDVar(name = "territories", columns = 1, rows = c(2, 14)) %>%
  setIDVar(name = "sublevel", columns = 1, rows = c(3, 8, 15)) %>%
  setIDVar(name = "year", columns = 7) %>%
  setIDVar(name = "commodities", columns = 2) %>%
  setObsVar(name = "harvested", columns = 5) %>%
  setObsVar(name = "production", columns = 6)

validateSchema(schema = schema, input = input) %>%
   getData(input = input)
#> # A tibble: 19 × 8
#>    X1        X2          X3    X4             X5        X6         X7     X8    
#>    <chr>     <chr>       <chr> <chr>          <chr>     <chr>      <chr>  <chr> 
#>  1 territory commodities NA    other_observed harvested production year   empty…
#>  2 group 1   NA          NA    NA             NA        NA         NA     NA    
#>  3 unit 1    NA          NA    NA             NA        NA         NA     NA    
#>  4 NA        soybean     NA    xyz            1111      1112       year 1 NA    
#>  5 NA        maize       NA    xyz            1121      1122       year 1 NA    
#>  6 NA        soybean     NA    xyz            1211      1212       year 2 NA    
#>  7 NA        maize       NA    xyz            1221      1222       year 2 NA    
#>  8 unit 2    NA          NA    NA             NA        NA         NA     NA    
#>  9 NA        soybean     NA    xyz            2111      2112       year 1 NA    
#> 10 NA        maize       NA    xyz            2121      2122       year 1 NA    
#> 11 NA        soybean     NA    xyz            2211      2212       year 2 NA    
#> 12 NA        maize       NA    xyz            2221      2222       year 2 NA    
#> 13 NA        NA          NA    NA             NA        NA         NA     NA    
#> 14 group 2   NA          NA    NA             NA        NA         NA     NA    
#> 15 unit 3    NA          NA    NA             NA        NA         NA     NA    
#> 16 NA        soybean     NA    xyz            3111      3112       year 1 NA    
#> 17 NA        maize       NA    xyz            3121      3122       year 1 NA    
#> 18 NA        soybean     NA    xyz            3211      3212       year 2 NA    
#> 19 NA        maize       NA    xyz            3221      3222       year 2 NA