/
getter_setter_s3_generics.R
243 lines (214 loc) · 5.98 KB
/
getter_setter_s3_generics.R
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
#' Set and get taxon authors
#'
#' Set and get taxon authors in objects that have them, such as [taxon_authority] objects.
#'
#' @param x An object with taxon authors.
#'
#' @examples
#' x <- taxon_authority(c('Cham. & Schldl.', 'L.'),
#' date = c('1827', '1753'))
#' tax_author(x)
#' tax_author(x)[1] <- "Billy"
#' tax_author(x) <- tolower(tax_author(x))
#'
#' @export
tax_author <- function(x) {
UseMethod('tax_author')
}
#' @rdname tax_author
#'
#' @param value The taxon authors to set. Inputs will be coerced into a [character] vector.
#'
#' @export
`tax_author<-` <- function(x, value) {
UseMethod('tax_author<-')
}
#' Set and get taxon authority dates
#'
#' Set and get the taxon authority dates in objects that have them, such as [taxon_authority] objects.
#'
#' @param x An object with taxon authority dates.
#'
#' @examples
#' x <- taxon_authority(c('Cham. & Schldl.', 'L.'),
#' date = c('1827', '1753'))
#' tax_date(x)
#' tax_date(x)[1] <- "1984"
#' tax_date(x) <- c(NA, '1800')
#'
#' @export
tax_date <- function(x) {
UseMethod('tax_date')
}
#' @rdname tax_date
#'
#' @param value The taxon authority dates to set. Inputs will be coerced into a [character] vector.
#'
#' @export
`tax_date<-` <- function(x, value) {
UseMethod('tax_date<-')
}
#' Set and get taxon authority citations
#'
#' Set and get the taxon authority citations in objects that have them, such as [taxon_authority] objects.
#'
#' @param x An object with taxon authority dates.
#'
#' @examples
#' x <- taxon_authority(c('Cham. & Schldl.', 'L.'),
#' date = c('1827', '1753'),
#' citation = c(NA, 'Species Plantarum'))
#' tax_cite(x)
#' tax_cite(x)[1] <- "Cham. et al 1984"
#'
#' @export
tax_cite <- function(x) {
UseMethod('tax_cite')
}
#' @rdname tax_cite
#'
#' @param value The taxon citations to set. Inputs will be coerced into a [taxon_authority] vector.
#'
#' @export
`tax_cite<-` <- function(x, value) {
UseMethod('tax_cite<-')
}
#' Set and get taxon ID databases
#'
#' Set and get the taxon ID databases in objects that have them, such as [taxon_id] objects.
#'
#' @param x An object with taxon authority dates.
#'
#' @examples
#' x <- taxon_id(c('9606', '1386', '4890', '4345'), db = 'ncbi')
#' tax_db(x)
#' tax_db(x) <- 'nbn'
#' tax_db(x)[2] <- 'itis'
#'
#' @export
tax_db <- function(x) {
UseMethod('tax_db')
}
#' @rdname tax_db
#'
#' @param value The taxon citations to set. Inputs will be coerced into a [taxon_db] vector.
#'
#' @export
`tax_db<-` <- function(x, value) {
UseMethod('tax_db<-')
}
#' Set and get taxon names
#'
#' Set and get the taxon names in objects that have them, such as [taxon] objects.
#' Note that this is not the same as adding vector names with [names].
#'
#' @param x An object with taxon names.
#'
#' @examples
#' x <- taxon(name = c('Homo sapiens', 'Bacillus', 'Ascomycota', 'Ericaceae'),
#' rank = c('species', 'genus', 'phylum', 'family'),
#' id = taxon_id(c('9606', '1386', '4890', '4345'), db = 'ncbi'),
#' auth = c('Linnaeus, 1758', 'Cohn 1872', NA, 'Juss., 1789'))
#'
#' tax_name(x)
#' tax_name(x) <- tolower(tax_name(x))
#' tax_name(x)[1] <- 'Billy'
#'
#' @export
tax_name <- function(x) {
UseMethod('tax_name')
}
#' @rdname tax_name
#'
#' @param value The taxon names to set. Inputs will be coerced into a [character] vector.
#'
#' @export
`tax_name<-` <- function(x, value) {
UseMethod('tax_name<-')
}
#' Set and get taxon IDs
#'
#' Set and get the taxon IDs in objects that have them, such as [taxon] objects.
#'
#' @param x An object with taxon IDs.
#'
#' @examples
#' x <- taxon(name = c('Homo sapiens', 'Bacillus', 'Ascomycota', 'Ericaceae'),
#' rank = c('species', 'genus', 'phylum', 'family'),
#' id = taxon_id(c('9606', '1386', '4890', '4345'), db = 'ncbi'),
#' auth = c('Linnaeus, 1758', 'Cohn 1872', NA, 'Juss., 1789'))
#'
#' tax_id(x)
#' tax_id(x) <- paste0('00', tax_id(x))
#' tax_id(x)[1] <- '00000'
#'
#' @export
tax_id <- function(x) {
UseMethod('tax_id')
}
#' @rdname tax_id
#'
#' @param value The taxon IDs to set. Inputs will be coerced into a [taxon_id] vector.
#'
#' @export
`tax_id<-` <- function(x, value) {
UseMethod('tax_id<-')
}
#' Set and get taxon authorities
#'
#' Set and get the taxon authorities in objects that have them, such as [taxon] objects.
#' Note that this sets all the authority information, such as author name, date, and citations.
#' To set or get just one of part of the authorities, use [tax_author], [tax_date], or [tax_cite] instead.
#'
#' @param x An object with taxon authorities.
#'
#' @examples
#' x <- taxon(name = c('Homo sapiens', 'Bacillus', 'Ascomycota', 'Ericaceae'),
#' rank = c('species', 'genus', 'phylum', 'family'),
#' id = taxon_id(c('9606', '1386', '4890', '4345'), db = 'ncbi'),
#' auth = c('Linnaeus, 1758', 'Cohn 1872', NA, 'Juss., 1789'))
#'
#' tax_auth(x)
#' tax_auth(x) <- tolower(tax_auth(x))
#' tax_auth(x)[1] <- 'Billy'
#'
#' @export
tax_auth <- function(x) {
UseMethod('tax_auth')
}
#' @rdname tax_auth
#'
#' @param value The taxon IDs to set. Inputs will be coerced into a [taxon_id] vector.
#'
#' @export
`tax_auth<-` <- function(x, value) {
UseMethod('tax_auth<-')
}
#' Set and get taxon ranks
#'
#' Set and get the taxon ranks in objects that have them, such as [taxon] objects.
#'
#' @param x An object with taxon ranks.
#'
#' @examples
#' x <- taxon(name = c('Homo sapiens', 'Bacillus', 'Ascomycota', 'Ericaceae'),
#' rank = c('species', 'genus', 'phylum', 'family'),
#' id = taxon_id(c('9606', '1386', '4890', '4345'), db = 'ncbi'),
#' auth = c('Linnaeus, 1758', 'Cohn 1872', NA, 'Juss., 1789'))
#'
#' tax_rank(x)
#' tax_rank(x) <- 'species'
#' tax_rank(x)[1] <- taxon_rank('family')
#'
#' @export
tax_rank <- function(x) {
UseMethod('tax_rank')
}
#' @rdname tax_rank
#'
#' @param value The taxon ranks to set. Inputs will be coerced into a [taxon_rank] vector.
#'
#' @export
`tax_rank<-` <- function(x, value) {
UseMethod('tax_rank<-')
}