-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAFA_secondary_functions
573 lines (536 loc) · 30.7 KB
/
AFA_secondary_functions
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
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
#Source functions for the AFA. Saved as AFA_secondary_functions.R
#Function to create canonical name from variables provided on the ACT plant cesus
canonical_name_for_ACT <- function(x) {
#if only genus, return NA
if(is.na(x[2])) {
return(NA)}
#if infraspecies is NA, then paste and collapse genus and species
if(is.na(x[3])) {
return(paste0(x[1:2], collapse = " "))}
#any other case, paste and collapse genus, species and infraspecies
else {
return(paste0(x[1:3], collapse = " "))}
}
#Function to create phrase species name
phrasespNSW <- function(x) {
#if no phrase name, return NA
if(is.na(x[2])& !is.na(x[1])) {
return(NA)}
#if phrase name, paste and collapse genus and phrase name
if(!is.na(x[2])& !is.na(x[1])) {
return(paste0(x[1:2], collapse = ""))}
}
#Function. Step 1 for creating canonical name
canonical_name_NSW1 <- function(x) {
#if there is no infraspecies, return species name
if(is.na(x[2])& !is.na(x[1])) {
return(paste0(x[1]))}
#if there is infraspecies, paste and collapse
if(!is.na(x[2])& !is.na(x[1])) {
return(paste0(x[1:2], collapse = " "))}
}
#Function. Step 1 for creating canonical name
canonical_name_TAS1 <- function(x) {
#if there is no infraspecies, return species name
if(is.na(x[2])& !is.na(x[1])) {
return(paste0(x[1]))}
#if there is infraspecies, paste and collapse
if(!is.na(x[2])& !is.na(x[1])) {
return(paste0(x[1:2], collapse = " "))}
}
#Function. Step 2 for creating canonical name
canonical_name_NSW2 <- function(x) {
#if there is no hybrids, return the canonical name obtained in the previous step
if(is.na(x[2])& !is.na(x[1])) {
return(paste0(x[1]))}
#if there are hybrids, paste and collapse
if(!is.na(x[2])& !is.na(x[1])) {
return(paste0(x[1:2], collapse = ""))}
}
#Function. Step 2 for creating canonical name
canonical_name_TAS2 <- function(x) {
#if there is no hybrids, return the canonical name obtained in the previous step
if(is.na(x[2])& !is.na(x[1])) {
return(paste0(x[1]))}
#if there are hybrids, paste and collapse
if(!is.na(x[2])& !is.na(x[1])) {
return(paste0(x[1:2], collapse = " "))}
}
#function to create canonical name from variables provided on the NT plant census
canonical_name_from_scratch <- function(x) {
#if only genus, return NA
if(is.na(x[2])) {
return(NA)}
#if infraspecies rank is NA, then paste and collapse genus and species
if(is.na(x[3])) {
return(paste0(x[1:2], collapse = " "))}
#if there is intraspecies rank, then paste and collapse genus, species, infraspecies rank and infraspecies epithet
else {
return(paste0(x[1:4], collapse = " "))}
} #close function
#same function than before but including authorship to create state name for the NT
state_name_from_scratch <- function(x) {
if(is.na(x[2])) {
return(NA)}
if(is.na(x[4])) {
return(paste0(x[1:3], collapse = " "))}
if(is.na(x[6])) {
return(paste0(x[1:5], collapse = " "))}
else {
return(paste0(x[1:6], collapse = " "))}
} #close function
#Function for TAS state name
state_name <- function(x) {
#if accepted name is NA, keep full name
if(is.na(x[1])) {
return(paste0(x[2]))}
#if accepted name as a record, keep accepted name
else {
return(paste0(x[1]))}
}
TAS_extinct_status <- function(x) {
# When extinct but with native origin, assign presumed extinct
if(is.na(x[1])) {
return(paste0(x[2]))
}
if(x[1] == "presumed extinct" && x[2]== "native") {
return(paste0(x[1]))
}
# When extinct but with alien origin, assign formerly introduced
if(x[1] == "presumed extinct" && x[2]== "introduced") {
return(paste0("formerly introduced"))
}
# When extinct and uncertain origin, assign presumed extinct
if(x[1] == "presumed extinct" && x[2]== "uncertain origin") {
return(paste0("presumed extinct"))
}
#for any other combination, paste status appearing in origin
else{
return(paste0(x[2]))}
} #close function
#function to assign correct status for extinct species, depending on their origin
VIC_extinct_status <- function(x) {
# When extinct but with native origin, assign presumed extinct
if(x[1] == "extinct" && x[2]== "native") {
return(paste0("presumed extinct"))
}
# When extinct but with alien origin, assign formerly introduced
if(x[1] == "extinct" && x[2]== "introduced") {
return(paste0("formerly introduced"))
}
# When extinct and uncertain origin, assign presumed extinct
if(x[1] == "extinct" && x[2]== "uncertain origin") {
return(paste0("presumed extinct"))
}
#for any other combination, paste status appearing in origin
else{
return(paste0(x[2]))}
} #close function
#Function. Step 1 for creating canonical name
canonical_name_GRIIS1 <- function(x) {
if(is.na(x[2])& !is.na(x[1])) {
return(paste0(x[1]))}
if(!is.na(x[2])) {
return(paste0(x[1:2], collapse = " "))}
}
#Function. Step 2 for creating canonical name
canonical_name_GRIIS2 <- function(x) {
#if there is no hybrids, return the canonical name obtained in the previous step
if(is.na(x[2])& !is.na(x[1])) {
return(paste0(x[1]))}
#if there are hybrids, paste and collapse
if(!is.na(x[2])& !is.na(x[1])) {
return(paste0(x[1:2], collapse = " "))}
}
compare_status <- function(x) { #where x will be a row of the input df
#When taxa_status == "excluded"
if(!is.na(x[4])) if(x[4] == "excluded") {
return("Taxon excluded on the APC")
}
if(is.na(x[4]) | x[4] != "excluded") {
# When NA in APC_Alien_Status --> write "Not listed on the APC with the name appearing on the state flora"
if(is.na(x[3])) {
return("Not listed on the APC with the name appearing on the state flora")
}
#When NA in APC_name --> write Not recorded on the APC as present in this state"
if(!is.na(x[3]) && is.na(x[2])) {
return("Not recorded on the APC as present in this state")
}
#When State_Alien_Status is NA
if(is.na(x[1])) {
return("Status not assigned on the state flora")
}
# When similar status in both columns --> write "Similar in state flora and APC"
if(x[1] == x[2]) {
return("Similar for the state flora and the APC")
}
# When differing --> write "According to the state flora is (copy --> State_Alien_Status), while according to the APC is (copy --> APC_Alien_Status)"
if(x[1] != x[2]) {
return(paste0("According to the state flora is ", x[1], ", while according to the APC is ", x[2]))
}
}
}
#function to return most conservative status
state_conservative_status <- function(x) { #where x will be a row of the input df
# When NA in APC_Alien_Status, copy status from state census
if(x[3] == "Taxon excluded on the APC") {
return(paste0(x[1]))
}
if(x[3] == "Not listed on the APC with the name appearing on the state flora") {
return(paste0(x[1]))
}
if(x[3] == "Not recorded on the APC as present in this state") {
return(paste0(x[1]))
}
# When similar status in both columns, copy status from state census
if(x[3] == "Similar for the state flora and the APC") {
return(paste0(x[1]))
}
# When status not assign on state flora, copy status from the APC
if(x[3] == "Status not assigned on the state flora") {
return(paste0(x[2]))
}
# When differing but the status on state flora is the most conservative, copy status from the state census
if(x[3] == "According to the state flora is native, while according to the APC is presumed extinct" ||
x[3] == "According to the state flora is native potentially colonising, while according to the APC is native" ||
x[3] == "According to the state flora is native potentially colonising, while according to the APC is presumed extinct" ||
x[3] == "According to the state flora is native colonising, while according to the APC is native potentially colonising" ||
x[3] == "According to the state flora is native colonising, while according to the APC is native" ||
x[3] == "According to the state flora is native colonising, while according to the APC is presumed extinct" ||
x[3] == "According to the state flora is uncertain origin, while according to the APC is native" ||
x[3] == "According to the state flora is uncertain origin, while according to the APC is native colonising" ||
x[3] == "According to the state flora is uncertain origin, while according to the APC is native potentially colonising" ||
x[3] == "According to the state flora is uncertain origin, while according to the APC is presumed extinct" ||
x[3] == "According to the state flora is formerly introduced, while according to the APC is uncertain origin" ||
x[3] == "According to the state flora is formerly introduced, while according to the APC is native colonising" ||
x[3] == "According to the state flora is formerly introduced, while according to the APC is native potentially colonising" ||
x[3] == "According to the state flora is formerly introduced, while according to the APC is native" ||
x[3] == "According to the state flora is formerly introduced, while according to the APC is presumed extinct" ||
x[3] == "According to the state flora is formerly naturalised, while according to the APC is formerly introduced" ||
x[3] == "According to the state flora is formerly naturalised, while according to the APC is uncertain origin" ||
x[3] == "According to the state flora is formerly naturalised, while according to the APC is native colonising" ||
x[3] == "According to the state flora is formerly naturalised, while according to the APC is native potentially colonising" ||
x[3] == "According to the state flora is formerly naturalised, while according to the APC is native" ||
x[3] == "According to the state flora is formerly naturalised, while according to the APC is presumed extinct" ||
x[3] == "According to the state flora is doubtfully introduced, while according to the APC is formerly naturalised" ||
x[3] == "According to the state flora is doubtfully introduced, while according to the APC is formerly introduced" ||
x[3] == "According to the state flora is doubtfully introduced, while according to the APC is uncertain origin" ||
x[3] == "According to the state flora is doubtfully introduced, while according to the APC is native colonising" ||
x[3] == "According to the state flora is doubtfully introduced, while according to the APC is native potentially colonising" ||
x[3] == "According to the state flora is doubtfully introduced, while according to the APC is native" ||
x[3] == "According to the state flora is doubtfully introduced, while according to the APC is presumed extinct" ||
x[3] == "According to the state flora is doubtfully naturalised, while according to the APC is introduced" ||
x[3] == "According to the state flora is doubtfully naturalised, while according to the APC is doubtfully introduced" ||
x[3] == "According to the state flora is doubtfully naturalised, while according to the APC is formerly naturalised" ||
x[3] == "According to the state flora is doubtfully naturalised, while according to the APC is formerly introduced" ||
x[3] == "According to the state flora is doubtfully naturalised, while according to the APC is uncertain origin" ||
x[3] == "According to the state flora is doubtfully naturalised, while according to the APC is native colonising" ||
x[3] == "According to the state flora is doubtfully naturalised, while according to the APC is native potentially colonising" ||
x[3] == "According to the state flora is doubtfully naturalised, while according to the APC is native" ||
x[3] == "According to the state flora is doubtfully naturalised, while according to the APC is presumed extinct" ||
x[3] == "According to the state flora is introduced, while according to the APC is doubtfully introduced" ||
x[3] == "According to the state flora is introduced, while according to the APC is formerly naturalised" ||
x[3] == "According to the state flora is introduced, while according to the APC is formerly introduced" ||
x[3] == "According to the state flora is introduced, while according to the APC is uncertain origin" ||
x[3] == "According to the state flora is introduced, while according to the APC is native colonising" ||
x[3] == "According to the state flora is introduced, while according to the APC is native potentially colonising"||
x[3] == "According to the state flora is introduced, while according to the APC is native" ||
x[3] == "According to the state flora is introduced, while according to the APC is presumed extinct" ||
x[3] == "According to the state flora is naturalised, while according to the APC is introduced" ||
x[3] == "According to the state flora is naturalised, while according to the APC is doubtfully naturalised" ||
x[3] == "According to the state flora is naturalised, while according to the APC is doubtfully introduced" ||
x[3] == "According to the state flora is naturalised, while according to the APC is formerly naturalised" ||
x[3] == "According to the state flora is naturalised, while according to the APC is formerly introduced" ||
x[3] == "According to the state flora is naturalised, while according to the APC is native colonising" ||
x[3] == "According to the state flora is naturalised, while according to the APC is native potentially colonising" ||
x[3] == "According to the state flora is naturalised, while according to the APC is native" ||
x[3] == "According to the state flora is naturalised, while according to the APC is presumed extinct") {
return(paste0(x[1]))
}
# When differing but the status on the APC is the most conservative, copy status from the APC
if(x[3] == "Status not assigned in the state flora" ||
x[3] == "According to the state flora is doubtfully naturalised, while according to the APC is naturalised" ||
x[3] == "According to the state flora is introduced, while according to the APC is naturalised" ||
x[3] == "According to the state flora is introduced, while according to the APC is doubtfully naturalised" ||
x[3] == "According to the state flora is doubtfully introduced, while according to the APC is naturalised" ||
x[3] == "According to the state flora is doubtfully introduced, while according to the APC is introduced" ||
x[3] == "According to the state flora is doubtfully introduced, while according to the APC is doubtfully naturalised" ||
x[3] == "According to the state flora is formerly naturalised, while according to the APC is naturalised" ||
x[3] == "According to the state flora is formerly naturalised, while according to the APC is introduced" ||
x[3] == "According to the state flora is formerly naturalised, while according to the APC is doubtfully naturalised" ||
x[3] == "According to the state flora is formerly naturalised, while according to the APC is doubtfully introduced" ||
x[3] == "According to the state flora is formerly introduced, while according to the APC is naturalised" ||
x[3] == "According to the state flora is formerly introduced, while according to the APC is introduced" ||
x[3] == "According to the state flora is formerly introduced, while according to the APC is doubtfully naturalised" ||
x[3] == "According to the state flora is formerly introduced, while according to the APC is doubtfully introduced" ||
x[3] == "According to the state flora is formerly introduced, while according to the APC is formerly naturalised" ||
x[3] == "According to the state flora is uncertain origin, while according to the APC is naturalised" ||
x[3] == "According to the state flora is uncertain origin, while according to the APC is introduced" ||
x[3] == "According to the state flora is uncertain origin, while according to the APC is doubtfully naturalised" ||
x[3] == "According to the state flora is uncertain origin, while according to the APC is doubtfully introduced" ||
x[3] == "According to the state flora is uncertain origin, while according to the APC is formerly naturalised" ||
x[3] == "According to the state flora is uncertain origin, while according to the APC is formerly introduced" ||
x[3] == "According to the state flora is native colonising, while according to the APC is naturalised" ||
x[3] == "According to the state flora is native colonising, while according to the APC is introduced" ||
x[3] == "According to the state flora is native colonising, while according to the APC is doubtfully naturalised" ||
x[3] == "According to the state flora is native colonising, while according to the APC is doubtfully introduced" ||
x[3] == "According to the state flora is native colonising, while according to the APC is formerly naturalised" ||
x[3] == "According to the state flora is native colonising, while according to the APC is formerly introduced" ||
x[3] == "According to the state flora is native colonising, while according to the APC is uncertain origin" ||
x[3] == "According to the state flora is native potentially colonising, while according to the APC is naturalised" ||
x[3] == "According to the state flora is native potentially colonising, while according to the APC is introduced" ||
x[3] == "According to the state flora is native potentially colonising, while according to the APC is doubtfully naturalised" ||
x[3] == "According to the state flora is native potentially colonising, while according to the APC is doubtfully introduced" ||
x[3] == "According to the state flora is native potentially colonising, while according to the APC is formerly naturalised" ||
x[3] == "According to the state flora is native potentially colonising, while according to the APC is formerly introduced" ||
x[3] == "According to the state flora is native potentially colonising, while according to the APC is uncertain origin" ||
x[3] == "According to the state flora is native potentially colonising, while according to the APC is native colonising" ||
x[3] == "According to the state flora is native, while according to the APC is naturalised" ||
x[3] == "According to the state flora is native, while according to the APC is introduced" ||
x[3] == "According to the state flora is native, while according to the APC is doubtfully naturalised" ||
x[3] == "According to the state flora is native, while according to the APC is doubtfully introduced" ||
x[3] == "According to the state flora is native, while according to the APC is formerly naturalised" ||
x[3] == "According to the state flora is native, while according to the APC is formerly introduced" ||
x[3] == "According to the state flora is native, while according to the APC is uncertain origin" ||
x[3] == "According to the state flora is native, while according to the APC is native colonising" ||
x[3] == "According to the state flora is native, while according to the APC is native potentially colonising" ||
x[3] == "According to the state flora is presumed extinct, while according to the APC is naturalised" ||
x[3] == "According to the state flora is presumed extinct, while according to the APC is introduced" ||
x[3] == "According to the state flora is presumed extinct, while according to the APC is doubtfully naturalised" ||
x[3] == "According to the state flora is presumed extinct, while according to the APC is doubtfully introduced" ||
x[3] == "According to the state flora is presumed extinct, while according to the APC is formerly naturalised" ||
x[3] == "According to the state flora is presumed extinct, while according to the APC is formerly introduced" ||
x[3] == "According to the state flora is presumed extinct, while according to the APC is uncertain origin" ||
x[3] == "According to the state flora is presumed extinct, while according to the APC is native colonising" ||
x[3] == "According to the state flora is presumed extinct, while according to the APC is native potentially colonising" ||
x[3] == "According to the state flora is presumed extinct, while according to the APC is native") {
return(paste0(x[2]))
}
}
#function to assign equivalences of Darwin Core degree of establishment
state_establishment_means <- function(x) { #where x will be a row of the input df
# When NA in APC_Alien_Status --> write "Not listed in APC with the name appearing in the state flora or listed but not recorded as present in this state"
if(is.na(x[1])){
return(NA)
}
if(x[1] == "native"||
x[1] == "native colonising"||
x[1] == "native potentially colonising") {
return(paste0("native"))
}
if(x[1] == "uncertain origin") {
return(paste0("uncertain"))
}
if(x[1] == "naturalised"||
x[1] == "doubtfully naturalised"||
x[1] == "formerly naturalised"||
x[1] == "introduced"||
x[1] == "doubtfully introduced") {
return(paste0("introduced"))
}
# When differing but state flora is most conservative
if(x[1] == "presumed extinct"||
x[1] == "formerly introduced"){
return(paste0("not enough information to assign establishment means"))
}
if(x[1] == "listed on the APC but not recorded anywhere"||
x[1] == "recorded only in external territories"){
return(NA)
}
}
#function to assign equivalences of Darwin Core degree of establishment at the state level
state_degree_of_establishment <- function(x) {
if(is.na(x[1])){
return(NA)
}
if(x[1] == "native"||
x[1] == "native colonising"||
x[1] == "native potentially colonising") {
return(paste0("native"))
}
if(x[1] == "uncertain origin") {
return(paste0("uncertain"))
}
if(x[1] == "naturalised"||
x[1] == "doubtfully naturalised"){
return(paste0("established"))
}
if(x[1] == "formerly naturalised"||
x[1] == "introduced"||
x[1] == "doubtfully introduced") {
return(paste0("not enough information to assign degree of establishment"))
}
# When differing but state flora is most conservative
if(x[1] == "presumed extinct"||
x[1] == "formerly introduced"){
return(paste0("not enough information to assign neither establishment means nor degree of establishment"))
}
}
#function to compare the status we elucidated at national scale with the one recorded on the GRIIS
compare_status_GRIIS <- function(x) { #where x will be a row of the input df
# When NA in APC_Alien_Status --> write "Not listed on the APC with the name appearing in the state flora or listed but not recorded as present in this state"
if(is.na(x[2])) {
return("Not listed on the GRIIS with the name appearing on the APC or not recorded as introduced at the national scale")
}
if(is.na(x[1])) {
return("Not recorded in Australian states or main territories, only in external territories")
}
# When similar status in both columns --> write "Similar in state flora and APC"
if(x[1] == x[2]) {
return("Similar for our national status and the GRIIS")
}
# When differing --> write "According to the state flora is (copy --> State_Alien_Status), while according to the APC is (copy --> APC_Alien_Status)"
if(x[1] != x[2]) {
return(paste0("According to our national status is ", x[1], ", while according to the GRIIS is ", x[2]))
}
}
return_conservative_status_GRIIS <- function(x) { #where x will be a row of the input df
# When NA in APC_Alien_Status --> write "Not listed in APC with the name appearing in the state flora or listed but not recorded as present in this state"
if(x[3] == "Not listed on the GRIIS with the name appearing on the APC or not recorded as introduced at national scale") {
return(paste0(x[1]))
}
# When similar status in both columns --> write "Similar in state flora and APC"
if(x[3] == "Not recorded in Australian states or main territories, only in external territories") {
return(NA)
}
# When similar status in both columns --> write "Similar in state flora and APC"
if(x[3] == "Similar for our national status and the GRIIS") {
return(paste0(x[1]))
}
# When differing and our national status is native, it states as native
if(x[3] == "According to our national status is native, while according to the GRIIS is introduced" ||
x[3] == "According to our national status is native colonising, while according to the GRIIS is introduced" ||
x[3] == "According to our national status is native colonising potential, while according to the GRIIS is introduced"||
x[3] == "According to our national status is uncertain origin, while according to the GRIIS is introduced" ||
x[3] == "According to our national status is presumed extinct, while according to the GRIIS is introduced" ||
x[3] == "According to our national status is native, while according to the GRIIS is harmful invasive" ||
x[3] == "According to our national status is native colonising, while according to the GRIIS is harmful invasive" ||
x[3] == "According to our national status is native colonising potential, while according to GRIIS is harmful invasive"||
x[3] == "According to our national status is presumed extinct, while according to the GRIIS is harmful invasive" ||
x[3] == "According to our national status is uncertain origin, while according to the GRIIS is harmful invasive") {
return(paste0(x[1]))
}
if(x[3] == "According to our national status is naturalised, while according to the GRIIS is harmful invasive"||
x[3] == "According to our national status is formerly naturalised, while according to the GRIIS is harmful invasive" ||
x[3] == "According to our national status is introduced, while according to the GRIIS is harmful invasive" ||
x[3] == "According to our national status is doubtfully naturalised, while according to the GRIIS is harmful invasive"||
x[3] == "According to our national status is doubtfully introduced, while according to the GRIIS is harmful invasive"||
x[3] == "According to our national status is formerly introduced, while according to the GRIIS is harmful invasive"||
x[3] == "According to our national status is doubtfully introduced, while according to the GRIIS is introduced"||
x[3] == "According to our national status is formerly introduced, while according to the GRIIS is introduced") {
return(paste0(x[2]))
}
# When differing but APC is most conservative
else {
return(paste0(x[1]))
}
}
national_establishment_means <- function(x) { #where x will be a row of the input df
# When NA in APC_Alien_Status --> write "Not listed on the APC with the name appearing on the state flora"
if(is.na(x[1])){
return(NA)
}
if(x[1] == "native"||
x[1] == "native colonising"||
x[1] == "native potentially colonising" ||
x[1] == "Mismatch with GRIIS. native") {
return(paste0("native"))
}
if(x[1] == "uncertain origin") {
return(paste0("uncertain"))
}
if(x[1] == "naturalised"||
x[1] == "harmful invasive"||
x[1] == "doubtfully naturalised"||
x[1] == "formerly naturalised"||
x[1] == "introduced"||
x[1] == "doubtfully introduced") {
return(paste0("introduced"))
}
# When differing but state flora is most conservative
if(x[1] == "presumed extinct"||
x[1] == "formerly introduced"){
return(paste0("not enough information to assign establishment means"))
}
if(x[1] == "listed in APC but not recorded anywhere"||
x[1] == "recorded only in external territories"){
return(NA)
}
}
#function for equivalences with DC terminology degree of establishment for status at the national scale
national_degree_of_establishment <- function(x) {
if(is.na(x[1])){
return(NA)
}
if(x[1] == "native") {
return(paste0("native"))
}
if(x[1] == "uncertain") {
return(NA)
}
if(x[1] == introduced && x[2] == "naturalised"||
x[1] == introduced && x[2] == "doubtfully naturalised") {
return(paste0("established"))
}
if(x[1] == introduced && x[2] == "harmful invasive") {
return(paste0("invasive"))
}
if(x[1] == introduced && x[2] == "introduced"||
x[1] == introduced && x[2] == "formerly naturalised"||
x[1] == introduced && x[2] == "formerly introduced"){
return(paste0("not enough information to assign degree of establishment"))
}
if(x[1] == "not enough information to assign establishment means"){
return(paste0("not enough information to assign neither establishment means nor degree of establishment"))
}
}
###########CROSS APC TAXONOMY WITH GBIF AND WFO############
#get canonical name
cross_GBIF <- function(dataset) {
cat('Starting cross reference process with GBIF. This can take some time')
column_name <- colnames(dataset) [grep("canonical", colnames(dataset))]
data_name <- subset(dataset, select=column_name)
#cross names with GBIF backbone without fuzzy matchign
GBIF <- name_backbone_checklist(data_name,verbose=FALSE)
#match ACT's canonical name with GBIF's verbatim name (i.e. the original name that GBIF's matching function used)
match_taxonomy <- match(data_name[,1], GBIF$verbatim_name)
#include on the main matrix both GBIF's canonical and scientific name based on matching
dataset$GBIF_canon_name <- GBIF$canonicalName[match_taxonomy]
dataset$GBIF_name <- GBIF$scientificName[match_taxonomy]
cat('Cross reference process with GBIF has now finished.')
return(dataset)
}
cross_WFO <- function(dataset) {
#download WFO
#WFO.download (WFO.url ="http://104.198.143.165/files/WFO_Backbone/_WFOCompleteBackbone/WFO_Backbone.zip", save.dir = getwd(), WFO.remember = TRUE)
#remember WFO
WFO.remember(WFO.file = NULL, WFO.data = "WFO.data", WFO.pos = 1)
column_name <- colnames(dataset) [grep("canonical", colnames(dataset))]
#match with WFO without fuzzy matching- and prioritising accepted species names
dataset1 <- WFO.match(spec.data= dataset, spec.name=column_name, WFO.data=WFO.data, Fuzzy=0, counter=1, verbose=FALSE)
dataset2 <- WFO.one(dataset1, priority = "Accepted")
#select the columns from WFO matching that we are interested in
WFO <- subset(dataset2, select= c('scientificName', 'scientificNameAuthorship'))
WFO$WFO_name <- paste(WFO$scientificName, WFO$scientificNameAuthorship)
WFO <- select(WFO, -scientificNameAuthorship)
dataset3 <- cbind(dataset, WFO)
dataset3 <- rename(dataset3, WFO_canon_name=scientificName)
dataset3$WFO_name <- str_replace_all(dataset3$WFO_name, "NA NA", "")
dataset3$WFO_name[dataset3$WFO_name==""] <- NA
return(dataset3)
}
###################
escape_curation_tasmania <- function(x) {
if(x[1] == "Medicago sativa L. nothosubsp * varia (Martyn) Arcang."){
return(paste0("Medicago sativa nothosubsp * varia"))
}
if(x[1] == "Medicago sativa L. nothosubsp x varia (Martyn) Arcang.") {
return(paste0("Medicago sativa nothosubsp x varia"))
}
else{
return(paste0(x[2]))
}
}
#########################################
#end of secondary functions
#########################################