filter_sites_by_md: Filter the sites by metadata variable values

Description Usage Arguments Details Value Examples

View source: R/getters.R

Description

filter_sites_by_md function takes logical expressions for the metadata variables (i.e. pl_sens_meth == 'HR'), and list the sites that met the criteria from thos supplied

Usage

1
filter_sites_by_md(sites, metadata, ..., .join = c("and", "or"))

Arguments

sites

character vector with the sites codes to filter, generally the result of sfn_sites_in_folder

metadata

metadata tbl object, usually the result of read_sfn_metadata

...

Logical expressions for the metadata variables, as in filter.

.join

Character indicating how to filter the sites, see details.

Details

.join argument indicates how sites must be filtered between metadata classes. 'and' indicates only sites meeting all conditions for all metadata classes are returned. 'or' indicates all sites meeting any condition between classes are returned. For two or more filtes of the same metadata class, they are combined as 'and'.

Value

A character vector with the sites fullfilling the premises

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# Let's access the data in "folder". This typically is the folder where the
# sapflow data at the desired unit level is (i.e. "RData/plant"), but in this
# example we will create a temporal folder with some data to test the function
folder <- tempdir()
save(ARG_TRE, file = file.path(folder, 'ARG_TRE.RData'))
save(ARG_MAZ, file = file.path(folder, 'ARG_MAZ.RData'))
save(AUS_CAN_ST2_MIX, file = file.path(folder, 'AUS_CAN_ST2_MIX.RData'))

# we need the metadata and the site names
metadata <- read_sfn_metadata(folder = folder, .write_cache = TRUE)
sites <- sfn_sites_in_folder(folder)

# Filter by Heat Ratio method
filter_sites_by_md(
  pl_sens_meth == 'HR', sites = sites, metadata = metadata
)

# Both, Heat Ratio and Heat Dissipation
filter_sites_by_md(
  pl_sens_meth %in% c('HR', 'HD'),
  sites = sites, metadata = metadata
)

# more complex, Heat Ratio method AND Woodland/Shrubland biome
filter_sites_by_md(
  pl_sens_meth == 'HR',
  si_biome == 'Woodland/Shrubland',
  sites = sites, metadata = metadata,
  .join = 'and' # default
)

# join = 'or' returns sites that meet any condition
filter_sites_by_md(
  pl_sens_meth == 'HR',
  si_biome == 'Woodland/Shrubland',
  sites = sites, metadata = metadata,
  .join = 'or'
)

sapfluxnetr documentation built on Aug. 28, 2020, 1:13 a.m.