These functions use dplyr-like selection syntax to quickly subset a mudata object by param, location, or dataset. Params, locations, an datasets can also be renamed using keyword arguments, identical to dplyr selection syntax.
select_datasets(.data, ...) # S3 method for default select_datasets(.data, ..., .factor = FALSE) select_locations(.data, ...) # S3 method for default select_locations(.data, ..., .factor = FALSE) select_params(.data, ...) # S3 method for default select_params(.data, ..., .factor = FALSE)
.data | A mudata object |
---|---|
... | Quoted names, bare names, or helpers like starts_with, contains, ends_with, one_of, or matches. |
.factor | If TRUE, the new object will keep the order specified by converting columns to factors. This may be useful for specifying order when using ggplot2. |
A subsetted mudata object.
# renaming can be handy when locations are verbosely named ns_climate %>% select_locations(sable_island = starts_with("SABLE"), nappan = starts_with("NAPPAN"), baddeck = starts_with("BADDECK")) %>% select_params(ends_with("temp"))#> A mudata object aligned along "date" #> distinct_datasets(): "ecclimate_monthly" #> distinct_locations(): "baddeck", "nappan" ... and 1 more #> distinct_params(): "extr_max_temp", "extr_min_temp" ... and 3 more #> src_tbls(): "data", "locations" ... and 3 more #> #> tbl_data() %>% head(): #> # A tibble: 6 x 7 #> dataset location param date value flag flag_text #> <chr> <chr> <chr> <date> <dbl> <chr> <chr> #> 1 ecclimate_monthly sable_island mean_max_temp 1897-01-01 NA M Missing #> 2 ecclimate_monthly sable_island mean_max_temp 1897-02-01 NA M Missing #> 3 ecclimate_monthly sable_island mean_max_temp 1897-03-01 NA M Missing #> 4 ecclimate_monthly sable_island mean_max_temp 1897-04-01 NA M Missing #> 5 ecclimate_monthly sable_island mean_max_temp 1897-05-01 NA M Missing #> 6 ecclimate_monthly sable_island mean_max_temp 1897-06-01 NA M Missing# can also use quoted values long_lake %>% select_params("Pb", "As", "Cr")#> A mudata object aligned along "depth" #> distinct_datasets(): "long_lake17" #> distinct_locations(): "LL GC10", "LL PC2" #> distinct_params(): "As", "Cr", "Pb" #> src_tbls(): "data", "locations" ... and 3 more #> #> tbl_data() %>% head(): #> # A tibble: 6 x 12 #> dataset location param depth value sd units zone n n_detect min_value #> <chr> <chr> <chr> <dbl> <dbl> <dbl> <chr> <chr> <int> <int> <dbl> #> 1 long_l… LL GC10 As 0.75 26 12.5 ppm Unit… 3 3 NA #> 2 long_l… LL GC10 As 2.25 30 NA ppm Unit… 1 1 NA #> 3 long_l… LL GC10 As 3.75 26 NA ppm Unit… 1 1 NA #> 4 long_l… LL GC10 As 5.25 25.3 6.51 ppm Unit… 3 3 NA #> 5 long_l… LL GC10 As 6.75 24 NA ppm Unit… 1 1 NA #> 6 long_l… LL GC10 As 8.25 37.3 14.0 ppm Unit… 3 3 NA #> # … with 1 more variable: max_value <dbl># can also use negative values to remove params/datasets/locations long_lake %>% select_params(-Pb)#> A mudata object aligned along "depth" #> distinct_datasets(): "long_lake17" #> distinct_locations(): "LL GC10", "LL PC2" #> distinct_params(): "14C_age", "As" ... and 14 more #> src_tbls(): "data", "locations" ... and 3 more #> #> tbl_data() %>% head(): #> # A tibble: 6 x 12 #> dataset location param depth value sd units zone n n_detect min_value #> <chr> <chr> <chr> <dbl> <dbl> <dbl> <chr> <chr> <int> <int> <dbl> #> 1 long_l… LL GC10 As 0.75 26 12.5 ppm Unit… 3 3 NA #> 2 long_l… LL GC10 As 2.25 30 NA ppm Unit… 1 1 NA #> 3 long_l… LL GC10 As 3.75 26 NA ppm Unit… 1 1 NA #> 4 long_l… LL GC10 As 5.25 25.3 6.51 ppm Unit… 3 3 NA #> 5 long_l… LL GC10 As 6.75 24 NA ppm Unit… 1 1 NA #> 6 long_l… LL GC10 As 8.25 37.3 14.0 ppm Unit… 3 3 NA #> # … with 1 more variable: max_value <dbl># to get around non-standard evaluation, use one_of() my_params <- c("Pb", "As", "Cr") long_lake %>% select_params(one_of(my_params))#> A mudata object aligned along "depth" #> distinct_datasets(): "long_lake17" #> distinct_locations(): "LL GC10", "LL PC2" #> distinct_params(): "As", "Cr", "Pb" #> src_tbls(): "data", "locations" ... and 3 more #> #> tbl_data() %>% head(): #> # A tibble: 6 x 12 #> dataset location param depth value sd units zone n n_detect min_value #> <chr> <chr> <chr> <dbl> <dbl> <dbl> <chr> <chr> <int> <int> <dbl> #> 1 long_l… LL GC10 As 0.75 26 12.5 ppm Unit… 3 3 NA #> 2 long_l… LL GC10 As 2.25 30 NA ppm Unit… 1 1 NA #> 3 long_l… LL GC10 As 3.75 26 NA ppm Unit… 1 1 NA #> 4 long_l… LL GC10 As 5.25 25.3 6.51 ppm Unit… 3 3 NA #> 5 long_l… LL GC10 As 6.75 24 NA ppm Unit… 1 1 NA #> 6 long_l… LL GC10 As 8.25 37.3 14.0 ppm Unit… 3 3 NA #> # … with 1 more variable: max_value <dbl>