filters.R 2.06 KB
Newer Older
Matija Obreza's avatar
Matija Obreza committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# Copyright 2018 Global Crop Diversity Trust
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

#' Make or adjust filter using MCPD terminology
#'
#' See FAO/Bioversity Multi-Crop Passport Descriptors.
#'
#' @param filter Existing filters (or blank list if not provided)
Matija Obreza's avatar
Matija Obreza committed
20
#' @param DOI Accession DOI
Matija Obreza's avatar
Matija Obreza committed
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#' @param ORIGCTY Country of origin
#' @param SAMPSTAT Biological status of sample
#'
#' @examples
#'  # Filter accessions from Mexico and Slovenia
#'  mcpd_filter(ORIGCTY = c("MEX", "SVN"))
#'
#'
#' @export
mcpd_filter <- function(filter = list(), DOI = NULL, ORIGCTY = NULL, SAMPSTAT = NULL) {
  f <- c(filter)

  f <- filter_DOI(f, DOI)
  f <- filter_ORIGCTY(f, ORIGCTY)
  f <- filter_SAMPSTAT(f, SAMPSTAT)

  f
}

#' Add filter on accession DOI
Matija Obreza's avatar
Matija Obreza committed
41
42
#' @param filter Existing filters (or blank list if not provided)
#' @param DOI Accession DOI
Matija Obreza's avatar
Matija Obreza committed
43
44
45
46
47
48
49
50
51
52
#' @export
filter_DOI <- function(filter = list(), DOI) {
  f <- c(filter)
  if (!is.null(DOI)) {
    f$doi = c(f$doi, DOI)
  }
  f
}

#' Add filter on Country of origin of material
Matija Obreza's avatar
Matija Obreza committed
53
54
#' @param filter Existing filters (or blank list if not provided)
#' @param ORIGCTY Country of origin
Matija Obreza's avatar
Matija Obreza committed
55
56
57
58
59
60
61
62
63
64
#' @export
filter_ORIGCTY <- function(filter = list(), ORIGCTY) {
  f <- c(filter)
  if (!is.null(ORIGCTY)) {
    f$orgCty.iso3 = c(f$orgCty.iso3, ORIGCTY)
  }
  f
}

#' Add filter on Biological status of sample
Matija Obreza's avatar
Matija Obreza committed
65
66
#' @param filter Existing filters (or blank list if not provided)
#' @param SAMPSTAT Biological status of sample
Matija Obreza's avatar
Matija Obreza committed
67
68
69
70
71
72
73
74
#' @export
filter_SAMPSTAT <- function(filter = list(), SAMPSTAT) {
  f <- c(filter)
  if (!is.null(SAMPSTAT)) {
    f$sampStat = c(f$sampStat, SAMPSTAT)
  }
  f
}