-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.Rhistory (Chriss-MacBook-Pro.local's conflicted copy 2020-03-18)
512 lines (512 loc) · 17.5 KB
/
.Rhistory (Chriss-MacBook-Pro.local's conflicted copy 2020-03-18)
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
preds_long <- preds_merged %>%
# Rename columns
rename(species_orig=X, species_closest=closestSp,
value=predVal, value_lo=lcl_predInt, value_hi=ucl_predInt) %>%
# Format columns
mutate(species_orig=gsub("_", " ", species_orig),
species_closest=gsub("_", " ", species_closest)) %>%
# Add nutrient
left_join(file_key, by="file") %>%
# Add units
left_join(select(key, type, nutrient, units), by="nutrient") %>%
mutate(nutrient_unit=paste0(nutrient, " (", units, ")")) %>%
# Rearrange columns
select(file, type, nutrient_unit, nutrient, units, everything())
# Reshape data
preds_wide <- preds_long %>%
select(nutrient, species_orig, value) %>%
spread(key="nutrient", value="value") %>%
# Rename columns
rename(protein_g="Protein",
fat_g="Total fat",
omega3_g="Omega-3 fatty acids",
omega6_g="Omega-6 fatty acids",
iron_mg="Iron",
zinc_mg="Zinc",
vitA_ug="Vitamin A",
vitB12_ug="Vitamin B12",
vitD_ug="Vitamin D")
# Check species names
spp_suggest_list <- freeR::suggest_names(preds_wide$species_orig)
spp_key <- tibble(species_orig=names(spp_suggest_list), species=NA)
for(i in 1:nrow(spp_key)){
spp_suggest <- spp_suggest_list[i][[1]]
spp_suggest1 <- ifelse(length(spp_suggest)==0, "", spp_suggest)
spp_key$species[i] <- spp_suggest1
}
# Add correct names to data and continue to correct
preds_wide1 <- preds_wide %>%
left_join(spp_key, by="species_orig") %>%
select(species, species_orig, everything()) %>%
mutate(species=ifelse(is.na(species), species_orig, species),
species=ifelse(species=="", species_orig, species)) %>%
mutate(species=recode(species,
# "Corydoras kristinae"="",
# "Cyprichromis jumbo"="",
# "Cyprichromis zebra"="",
"Hemibarbus longibarbis"="Hemibarbus maculatus",
# "Macrocephenchelys soela"="",
# "Puntius parvus"="",
"Sebastes marinus"="Sebastes norvegicus", # WORMS
"Takifugu fasciatus"="Takifugu fasciatus"))
# Check names
freeR::check_names(preds_wide1$species)
# Add commmon names
rfishbase::sci_to_common(preds_wide1$species)
?freeR::fishbase
# Check names
spp_key <- freeR::fishbase(dataset="species", species=preds_wide1$species, cleaned=T)
View(spp_key)
freeR::complete(spp_key)
# Try 1. FishBase species page
spp_key <- freeR::fishbase(dataset="species", species=species, cleaned=F)
species <- preds_wide1$species[1:20]
# Try 1. FishBase species page
spp_key <- freeR::fishbase(dataset="species", species=species, cleaned=F)
spp_key1 <- spp_key %>%
select(species, comm_name)
View(spp_key)
spp_key1 <- spp_key %>%
select(species, comm_name)
View(spp_key)
# Try 1. FishBase species page
spp_key <- freeR::fishbase(dataset="species", species=species, cleaned=T)
spp_key1 <- spp_key %>%
select(species, comm_name)
View(spp_key1)
spp_key1 <- spp_key %>%
select(species, comm_name) %>%
arrange(comm_name)
spp_key1 <- spp_key %>%
select(species, comm_name) %>%
arrange(comm_name)
# Try 2. FishBase common name page
spp_missing <- spp_key1$species[is.na(spp_key1$comm_name)]
spp_missing
?sci_to_common
spp_key2 <- rfishbase::sci_to_common(species_list=spp_missing, server = "fishbase")
View(spp_key2)
spp_key2_english <- spp_key2 %>%
filter(Language=="English") %>%
select(Species, CommName) %>%
rename(species=Species, comm_name=CommName)
spp_key2_english <- spp_key2 %>%
filter(Language=="English") %>%
select(Species, ComName) %>%
rename(species=Species, comm_name=ComName)
View(spp_key2_english)
species <- preds_wide1$species[1:100]
# Try 1. FishBase species page
spp_key1_orig <- freeR::fishbase(dataset="species", species=species, cleaned=T)
spp_key1 <- spp_key1_orig %>%
select(species, comm_name) %>%
arrange(comm_name)
spp_key1
# Try 2. FishBase common name page
spp_missing_from_try1 <- spp_key1$species[is.na(spp_key1$comm_name)]
spp_missing_from_try1
spp_key2_orig <- rfishbase::sci_to_common(species_list= spp_missing_from_try1, server = "fishbase")
spp_key2 <- spp_key2 %>%
filter(Language=="English") %>%
select(Species, ComName) %>%
rename(species=Species, comm_name=ComName)
spp_missing_from_try1
# Try 2. FishBase common name page (English names)
spp_missing_from_try1 <- spp_key1$species[is.na(spp_key1$comm_name)]
spp_key2_orig <- rfishbase::sci_to_common(species_list= spp_missing_from_try1, server = "fishbase")
spp_key2_orig <- rfishbase::sci_to_common(species_list= spp_missing_from_try1, server = "fishbase")
spp_key2_orig
spp_key2_inv_orig <- rfishbase::sci_to_common(species_list= spp_missing_from_try1, server = "sealifebase")
View(spp_key2_inv_orig)
spp_key2_orig <- rbind(spp_key2_fin_orig, spp_key2_inv_orig) %>%
filter(!is.na(ComName))
spp_key2_fin_orig <- rfishbase::sci_to_common(species_list= spp_missing_from_try1, server = "fishbase")
spp_key2_orig <- rbind(spp_key2_fin_orig, spp_key2_inv_orig) %>%
filter(!is.na(ComName))
View(spp_key2_orig)
spp_key2_eng <- spp_key2_orig %>%
filter(Language=="English") %>%
select(Species, ComName) %>%
rename(species=Species, comm_name=ComName)
View(spp_key2_english)
spp_key2_orig <- rbind(spp_key2_fin_orig, spp_key2_inv_orig) %>%
filter(!is.na(ComName))
spp_key2_eng <- spp_key2_orig %>%
filter(Language=="English") %>%
select(Species, ComName) %>%
rename(species=Species, comm_name=ComName)
View(spp_key2_fin_orig)
rbind(spp_key2_fin_orig, spp_key2_inv_orig)
spp_key2_orig <- rbind(spp_key2_fin_orig, spp_key2_inv_orig) %>%
filter(!is.na(ComName))
View(spp_key2_orig)
spp_key2_eng <- spp_key2_orig %>%
filter(Language=="English")
table(spp_key2_orig$Language)
View(spp_key2_eng)
spp_key2_eng <- spp_key2_orig %>%
filter(Language=="English") %>%
select(Species, ComName) %>%
rename(species=Species, comm_name=ComName)
spp_key1 <- spp_key1_orig %>%
select(species, comm_name) %>%
filter(!is.na(comm_name))
species[!species %in% spp_key1$species]
# Try 2. FishBase common name page (English names)
spp_missing_from_try1 <- species[!species %in% spp_key1$species]
# Try 3. FishBase common name page (not English)
spp_done <- c(spp_key1$species, spp_key2_eng$species)
spp_missing_from_try12 <- species[!species %in% spp_done]
spp_missing_from_try12
spp_key3_orig <- spp_key2_orig %>%
filter(Language!="English")
spp_key3_orig <- spp_key2_orig %>%
filter(species %in% spp_missing_from_try12)
spp_missing_from_try12 <- species[!species %in% spp_done]
spp_missing_from_try12
spp_key3_orig <- spp_key2_orig %>%
filter(species %in% spp_missing_from_try12)
spp_key3_orig <- spp_key2_orig %>%
filter(Species %in% spp_missing_from_try12)
View(spp_key3_orig)
spp_key3_orig <- spp_key2_orig %>%
# Remove species already completed
filter(Species %in% spp_missing_from_try12) %>%
# Remove species with punctuation
filter(grepl("::punct::", Species))
spp_key3_orig <- spp_key2_orig %>%
# Remove species already completed
filter(Species %in% spp_missing_from_try12) %>%
# Remove species with punctuation
filter(grepl("[:punct:]", Species))
spp_key3_orig <- spp_key2_orig %>%
# Remove species already completed
filter(Species %in% spp_missing_from_try12) %>%
# Remove species with punctuation
filter(!grepl("[:punct:]", Species))
spp_key3_orig <- spp_key2_orig %>%
# Remove species already completed
filter(Species %in% spp_missing_from_try12) %>%
# Remove species with punctuation
filter(grepl("[:punct:]", Species))
spp_key3_orig <- spp_key2_orig %>%
# Remove species already completed
filter(Species %in% spp_missing_from_try12) %>%
# Remove species with punctuation
filter(grepl("[[:punct:]]", Species))
spp_key3_orig <- spp_key2_orig %>%
# Remove species already completed
filter(Species %in% spp_missing_from_try12) %>%
# Remove species with punctuation
filter(grepl("[:punct:]", Species))
spp_key3_orig <- spp_key2_orig %>%
# Remove species already completed
filter(Species %in% spp_missing_from_try12) %>%
# Remove species with punctuation
filter(!grepl("[:punct:]", Species))
spp_key3_orig <- spp_key2_orig %>%
# Remove species already completed
filter(Species %in% spp_missing_from_try12) %>%
# Remove species with punctuation
filter(!grepl("[[:punct:]]", Species))
View(spp_key3_orig)
spp_key3_orig <- spp_key2_orig %>%
# Remove species already completed
filter(Species %in% spp_missing_from_try12) %>%
# Remove species with punctuation
filter(grepl("[[:punct:]]", Species))
!
spp_key3_orig <- spp_key2_orig %>%
# Remove species already completed
filter(Species %in% spp_missing_from_try12)
spp_key3_orig <- spp_key2_orig %>%
# Remove species already completed
filter(Species %in% spp_missing_from_try12)
View(spp_key3_orig)
spp_key3_orig <- spp_key2_orig %>%
# Remove species already completed
filter(Species %in% spp_missing_from_try12) %>%
# Remove species with ?s
filter(grepl("?", Species))
spp_key3_orig <- spp_key2_orig %>%
# Remove species already completed
filter(Species %in% spp_missing_from_try12) %>%
# Remove species with ?s
filter(grepl("/?", Species))
spp_key3_orig <- spp_key2_orig %>%
# Remove species already completed
filter(Species %in% spp_missing_from_try12) %>%
# Remove species with ?s
filter(grepl("\\?", Species))
View(spp_key3_orig)
spp_key3_orig <- spp_key2_orig %>%
# Remove species already completed
filter(Species %in% spp_missing_from_try12) %>%
# Remove species with ?s
filter(grepl("\?", Species))
?grepls
?grepl
grepl("\?", spp_key2_orig$Species)
grepl("\\?", spp_key2_orig$Species)
spp_key3_orig <- spp_key2_orig %>%
# Remove species already completed
filter(Species %in% spp_missing_from_try12) %>%
# Remove species with ?s
filter(grepl("\\?", Species))
str(spp_key2_orig)
spp_key3_orig <- spp_key2_orig %>%
# Remove species already completed
filter(Species %in% spp_missing_from_try12) %>%
# Remove species with ?s
filter(grepl("\\?", Species %>% as.character()))
spp_key3_orig <- spp_key2_orig %>%
# Remove species already completed
filter(Species %in% spp_missing_from_try12) %>%
# Remove species with ?s
filter(grep("\\?", Species))
spp_key3_orig <- spp_key2_orig %>%
# Remove species already completed
filter(Species %in% spp_missing_from_try12) %>%
# Remove species with ?s
filter(grepl("\\?", ComName))
View(spp_key3_orig)
spp_key3_orig <- spp_key2_orig %>%
# Remove species already completed
filter(Species %in% spp_missing_from_try12) %>%
# Remove species with ?s
filter(!grepl("\\?", ComName))
spp_key3_orig <- spp_key2_orig %>%
# Remove species already completed
filter(Species %in% spp_missing_from_try12) %>%
# Remove common name with ?s
filter(!grepl("\\?", ComName)) %>%
# Remove common names with punctuation
filter(!grepl("[:punct:]", ComName))
spp_key3_orig <- spp_key2_orig %>%
# Remove species already completed
filter(Species %in% spp_missing_from_try12) %>%
# Remove common name with ?s
filter(!grepl("\\?", ComName)) %>%
# Remove common names with punctuation
filter(!grepl("[:punct:]", ComName)) %>%
# Take first option
group_by(Species) %>%
slice(1)
spp_key3_orig <- spp_key2_orig %>%
# Remove species already completed
filter(Species %in% spp_missing_from_try12) %>%
# Remove common name with ?s
filter(!grepl("\\?", ComName)) %>%
# Remove common names with punctuation
# filter(!grepl("[:punct:]", ComName)) %>%
# Take first option
group_by(Species) %>%
slice(1) %>%
# Format columns
select(Species, ComName) %>%
rename(species=Species, ComName=comm_name)
spp_key3_orig <- spp_key2_orig %>%
# Remove species already completed
filter(Species %in% spp_missing_from_try12) %>%
# Remove common name with ?s
filter(!grepl("\\?", ComName)) %>%
# Remove common names with punctuation
# filter(!grepl("[:punct:]", ComName)) %>%
# Take first option
group_by(Species) %>%
slice(1) %>%
# Format columns
select(Species, ComName) %>%
rename(species=Species, comm_name=ComName)
View(spp_key3_orig)
spp_key3_orig <- spp_key2_orig %>%
# Remove species already completed
filter(Species %in% spp_missing_from_try12) %>%
# Remove common name with ?s
filter(!grepl("\\?", ComName)) %>%
# Remove common names with punctuation
filter(!grepl("[:punct:]", ComName)) %>%
# Take first option
group_by(Species) %>%
slice(1) %>%
# Format columns
select(Species, ComName) %>%
rename(species=Species, comm_name=ComName)
View(spp_key3_orig)
spp_key3 <- spp_key2_orig %>%
# Remove species already completed
filter(Species %in% spp_missing_from_try12) %>%
# Remove common name with ?s
filter(!grepl("\\?", ComName)) %>%
# Remove common names with punctuation
filter(!grepl("[:punct:]", ComName)) %>%
# Take first option
group_by(Species) %>%
slice(1) %>%
# Format columns
select(Species, ComName) %>%
rename(species=Species, comm_name=ComName)
spp_key2 <- spp_key2_orig %>%
filter(Language=="English") %>%
select(Species, ComName) %>%
rename(species=Species, comm_name=ComName)
spp_key2_orig <- rbind(spp_key2_fin_orig, spp_key2_inv_orig) %>%
filter(!is.na(ComName))
spp_key2 <- spp_key2_orig %>%
filter(Language=="English") %>%
select(Species, ComName) %>%
rename(species=Species, comm_name=ComName)
# Try 3. FishBase common name page (not English)
spp_done <- c(spp_key1$species, spp_key2_eng$species)
spp_missing_from_try12 <- species[!species %in% spp_done]
spp_key3 <- spp_key2_orig %>%
# Remove species already completed
filter(Species %in% spp_missing_from_try12) %>%
# Remove common name with ?s
filter(!grepl("\\?", ComName)) %>%
# Remove common names with punctuation
filter(!grepl("[:punct:]", ComName)) %>%
# Take first option
group_by(Species) %>%
slice(1) %>%
# Format columns
select(Species, ComName) %>%
rename(species=Species, comm_name=ComName)
# Merge names
spp_key <- rbind(spp_key1, spp_key2, spp_key3)
anyDuplicated(spp_key$species)
View(spp_key)
spp_key3 <- spp_key2_orig %>%
# Remove species already completed
filter(Species %in% spp_missing_from_try12) %>%
# Remove common name with ?s
filter(!grepl("\\?", ComName)) %>%
# Remove common names with punctuation
filter(!grepl("[:punct:]", ComName)) %>%
# Take first option
group_by(Species) %>%
slice(1) %>%
# Format columns
select(Species, ComName) %>%
rename(species=Species, comm_name=ComName)
View(spp_key3)
spp_key3 <- spp_key2_orig %>%
# Remove species already completed
filter(Species %in% spp_missing_from_try12) %>%
# Remove common name with ?s
filter(!grepl("\\?", ComName)) %>%
# Remove common names with punctuation
filter(!grepl("[:punct:]", ComName)) %>%
# Take first option
group_by(Species) %>%
slice(1) %>%
# Format columns
select(Species, ComName) %>%
rename(species=Species, comm_name=ComName) %>%
ungroup()
# Merge names
spp_key <- rbind(spp_key1, spp_key2, spp_key3)
View(spp_key)
spp_key3 <- spp_key2_orig %>%
# Remove species already completed
filter(Species %in% spp_missing_from_try12) %>%
# Remove common name with ?s
filter(!grepl("\\?", ComName)) %>%
# Remove common names with punctuation
# filter(!grepl("[:punct:]", ComName)) %>%
# Take first option
group_by(Species) %>%
slice(1) %>%
# Format columns
select(Species, ComName) %>%
rename(species=Species, comm_name=ComName) %>%
ungroup()
# Merge names
spp_key <- rbind(spp_key1, spp_key2, spp_key3)
# Try 1. FishBase species page
spp_key1_orig <- freeR::fishbase(dataset="species", species=species, cleaned=T)
spp_key1 <- spp_key1_orig %>%
select(species, comm_name) %>%
filter(!is.na(comm_name))
# Try 2. FishBase common name page (English names)
spp_missing_from_try1 <- species[!species %in% spp_key1$species]
spp_key2_fin_orig <- rfishbase::sci_to_common(species_list= spp_missing_from_try1, server = "fishbase")
spp_key2_inv_orig <- rfishbase::sci_to_common(species_list= spp_missing_from_try1, server = "sealifebase")
spp_key2_orig <- rbind(spp_key2_fin_orig, spp_key2_inv_orig) %>%
filter(!is.na(ComName))
spp_key2 <- spp_key2_orig %>%
filter(Language=="English") %>%
select(Species, ComName) %>%
rename(species=Species, comm_name=ComName)
spp_missing_from_try1
species <- preds_wide1$species
# Try 1. FishBase species page
spp_key1_orig <- freeR::fishbase(dataset="species", species=species, cleaned=T)
spp_key1 <- spp_key1_orig %>%
select(species, comm_name) %>%
filter(!is.na(comm_name))
# Try 2. FishBase common name page (English names)
spp_missing_from_try1 <- species[!species %in% spp_key1$species]
spp_key2_fin_orig <- rfishbase::sci_to_common(species_list= spp_missing_from_try1, server = "fishbase")
spp_key2_inv_orig <- rfishbase::sci_to_common(species_list= spp_missing_from_try1, server = "sealifebase")
spp_key2_orig <- rbind(spp_key2_fin_orig, spp_key2_inv_orig) %>%
filter(!is.na(ComName))
spp_key2 <- spp_key2_orig %>%
filter(Language=="English") %>%
select(Species, ComName) %>%
rename(species=Species, comm_name=ComName)
# Try 3. FishBase common name page (not English)
spp_done <- c(spp_key1$species, spp_key2$species)
spp_missing_from_try12 <- species[!species %in% spp_done]
spp_key3 <- spp_key2_orig %>%
# Remove species already completed
filter(Species %in% spp_missing_from_try12) %>%
# Remove common name with ?s
filter(!grepl("\\?", ComName)) %>%
# Remove common names with punctuation
# filter(!grepl("[:punct:]", ComName)) %>%
# Take first option
group_by(Species) %>%
slice(1) %>%
# Format columns
select(Species, ComName) %>%
rename(species=Species, comm_name=ComName) %>%
ungroup()
# Merge names
spp_key <- rbind(spp_key1, spp_key2, spp_key3)
spp_key3 <- spp_key2_orig %>%
# Remove species already completed
filter(Species %in% spp_missing_from_try12) %>%
# Remove common name with ?s
filter(!grepl("\\?", ComName)) %>%
# Remove common names with punctuation
filter(!grepl("[:punct:]", ComName)) %>%
# Take first option
group_by(Species) %>%
slice(1) %>%
# Format columns
select(Species, ComName) %>%
rename(species=Species, comm_name=ComName) %>%
ungroup()
# Merge names
spp_key <- rbind(spp_key1, spp_key2, spp_key3)
spp_key3 <- spp_key2_orig %>%
# Remove species already completed
filter(Species %in% spp_missing_from_try12) %>%
# Remove common name with ?s
filter(!grepl("\\?", ComName)) %>%
# Remove common names with punctuation
# filter(!grepl("[:punct:]", ComName)) %>%
# Take first option
group_by(Species) %>%
slice(1) %>%
# Format columns
select(Species, ComName) %>%
rename(species=Species, comm_name=ComName) %>%
ungroup()
# Merge names
spp_key <- rbind(spp_key1, spp_key2, spp_key3)
View(spp_key)
# Merge names
spp_key <- rbind(spp_key1, spp_key2, spp_key3) %>%
arrange(species)