All pluck funtions are wrappers around dplyr::filter()
. The dots arguments are converted in a vector and then each
function searchs the specific column with the %in%
operator.
Usage
pluck_parameter(data, ...)
pluck_interval(data, ...)
pluck_site(data, ...)
pluck_unit(data, ...)
pluck_year(data, ...)
Windows, symbols and encodings
The first implementation supported symbols as dots arguments. On windows the symbol gets converted to the native
encoding without the encoding mark. Is the converted symbol now compared to UTF-8 strings it doesn't match. One
example would be strings like "°C" or "µg/m3". See rlang::as_string()
Examples
fn <- system.file("extdata", "smn_multi.txt", package = "rOstluft.data")
data <- read_smn_multiple(fn) %>% dplyr::arrange(starttime)
pluck_parameter(data, "ta1towb0")
#> # A tibble: 6 × 6
#> starttime site parameter interval unit value
#> <dttm> <fct> <fct> <fct> <fct> <dbl>
#> 1 2010-01-01 00:00:00 UEB ta1towb0 h1 NA 3.7
#> 2 2010-01-01 01:00:00 UEB ta1towb0 h1 NA 3.5
#> 3 2010-01-01 02:00:00 UEB ta1towb0 h1 NA 3.2
#> 4 2010-01-01 03:00:00 UEB ta1towb0 h1 NA 3.1
#> 5 2010-01-01 04:00:00 UEB ta1towb0 h1 NA 3.3
#> 6 2010-01-01 05:00:00 UEB ta1towb0 h1 NA 3.3
# strings or symbols
pluck_site(data, "KLO", "UEB")
#> # A tibble: 267 × 6
#> starttime site parameter interval unit value
#> <dttm> <fct> <fct> <fct> <fct> <dbl>
#> 1 2010-01-01 00:00:00 KLO dkl010b0 h1 NA 319
#> 2 2010-01-01 00:00:00 KLO fkl010b0 h1 NA 1.5
#> 3 2010-01-01 00:00:00 KLO gre000b0 h1 NA 0
#> 4 2010-01-01 00:00:00 KLO tre200b0 h1 NA 2.3
#> 5 2010-01-01 00:00:00 UEB dk1towb0 h1 NA 249
#> 6 2010-01-01 00:00:00 UEB fk1towb0 h1 NA 1.7
#> 7 2010-01-01 00:00:00 UEB ta1towb0 h1 NA 3.7
#> 8 2010-01-01 01:00:00 KLO dkl010b0 h1 NA 317
#> 9 2010-01-01 01:00:00 KLO fkl010b0 h1 NA 1.7
#> 10 2010-01-01 01:00:00 KLO gre000b0 h1 NA 0
#> # ℹ 257 more rows
# supports splicing with !!!
intervals = c("h1", "d1")
pluck_interval(data, !!!intervals) %>% dplyr::slice(40:45)
#> # A tibble: 6 × 6
#> starttime site parameter interval unit value
#> <dttm> <fct> <fct> <fct> <fct> <dbl>
#> 1 2010-01-01 05:00:00 UEB dk1towb0 h1 NA 129
#> 2 2010-01-01 05:00:00 UEB fk1towb0 h1 NA 1.9
#> 3 2010-01-01 05:00:00 UEB ta1towb0 h1 NA 3.3
#> 4 2017-12-31 01:00:00 RHW wkcap1d0 d1 NA 2
#> 5 2017-12-31 01:00:00 RHW wkcap2d0 d1 NA 11
#> 6 2017-12-31 01:00:00 RHW wkcap3d0 d1 NA 21
# pluck_year supports vector
pluck_year(data, 2010:2012)
#> # A tibble: 42 × 6
#> starttime site parameter interval unit value
#> <dttm> <fct> <fct> <fct> <fct> <dbl>
#> 1 2010-01-01 00:00:00 KLO dkl010b0 h1 NA 319
#> 2 2010-01-01 00:00:00 KLO fkl010b0 h1 NA 1.5
#> 3 2010-01-01 00:00:00 KLO gre000b0 h1 NA 0
#> 4 2010-01-01 00:00:00 KLO tre200b0 h1 NA 2.3
#> 5 2010-01-01 00:00:00 UEB dk1towb0 h1 NA 249
#> 6 2010-01-01 00:00:00 UEB fk1towb0 h1 NA 1.7
#> 7 2010-01-01 00:00:00 UEB ta1towb0 h1 NA 3.7
#> 8 2010-01-01 01:00:00 KLO dkl010b0 h1 NA 317
#> 9 2010-01-01 01:00:00 KLO fkl010b0 h1 NA 1.7
#> 10 2010-01-01 01:00:00 KLO gre000b0 h1 NA 0
#> # ℹ 32 more rows
# NAs in data aren't a problem
pluck_unit(data, "hPa")
#> # A tibble: 6 × 6
#> starttime site parameter interval unit value
#> <dttm> <fct> <fct> <fct> <fct> <dbl>
#> 1 2019-01-31 00:50:00 TAE prestas0 min10 hPa 936.
#> 2 2019-01-31 01:00:00 TAE prestas0 min10 hPa 936
#> 3 2019-01-31 01:10:00 TAE prestas0 min10 hPa 936.
#> 4 2019-01-31 01:20:00 TAE prestas0 min10 hPa 936.
#> 5 2019-01-31 01:30:00 TAE prestas0 min10 hPa 936.
#> 6 2019-01-31 01:40:00 TAE prestas0 min10 hPa 936.
# pipe friendly
data %>%
pluck_site("KLO", "UEB") %>%
pluck_parameter("gre000z0") %>%
pluck_year(2010:2018)
#> # A tibble: 12 × 6
#> starttime site parameter interval unit value
#> <dttm> <fct> <fct> <fct> <fct> <dbl>
#> 1 2018-01-01 00:50:00 KLO gre000z0 min10 NA 1
#> 2 2018-01-01 00:50:00 UEB gre000z0 min10 NA 3
#> 3 2018-01-01 01:00:00 KLO gre000z0 min10 NA 1
#> 4 2018-01-01 01:00:00 UEB gre000z0 min10 NA 3
#> 5 2018-01-01 01:10:00 KLO gre000z0 min10 NA 1
#> 6 2018-01-01 01:10:00 UEB gre000z0 min10 NA 2
#> 7 2018-01-01 01:20:00 KLO gre000z0 min10 NA 2
#> 8 2018-01-01 01:20:00 UEB gre000z0 min10 NA 2
#> 9 2018-01-01 01:30:00 KLO gre000z0 min10 NA 3
#> 10 2018-01-01 01:30:00 UEB gre000z0 min10 NA 2
#> 11 2018-01-01 01:40:00 KLO gre000z0 min10 NA 4
#> 12 2018-01-01 01:40:00 UEB gre000z0 min10 NA 2