-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path.Rhistory
512 lines (512 loc) · 39.3 KB
/
.Rhistory
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
date = as.Date(Sys.time()) # Create Date
date = gsub("-","_",date)
filename = paste("./HerbiTraits_2020_10_01/Changes/3_Output/HerbiTraits_S2_",date,".csv", sep ="") #Create filename
## Save
write.csv(herbiTraits_Master, file = filename)
######################################################################!
# #
# Script 3: CHECK THE MASS METADATA #
# #
######################################################################!
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# METADATA
# This script checks the references
#
# Output: an updated dataframe with cleaned up references in the form of a csv file. Also an excel file for further processing
# time: less than 1 min
# Status: under construction (23 September 2020)
#
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––####
##### 1. PREPARING THE DATA #####
#–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––####
# – Clear Memory ####
#–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
rm(list = ls()) # clean memory (= remove)
graphics.off() # close graphic windows
# – Set working directory ####
#–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
setwd("/Users/au572919/Research/herbiTraits")
getwd()
# – Set up libraries ####
#–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
# – Load Data ####
#–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
#~~ EXPLANATION ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
# This script combines the csv files created by S1 and S2. These CSV files have their creation date in their name to keep track of the most recent version.
# This means there may be many trait files in the output folder. The following lines of code just select the most recent trait dataset, based on the creation date in the filename.
#
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
## Locate all trait datasets that S2 created.
files_in_folder = list.files(path = "./HerbiTraits_2020_10_01/Changes/3_Output") # list all the files occurring is the folder
Trait_Datasets = files_in_folder[which(grepl(pattern = "HerbiTraits_S2_",files_in_folder, fixed = TRUE))] # take all the Bird Trait Files
## Select the most recent version of the datasets
Trait_Datasets = tail(sort(Trait_Datasets), n=1)
## Load HerbiTraits Data
herbiTraits_Master = read.csv(paste("./HerbiTraits_2020_10_01/Changes/3_Output/", Trait_Datasets, sep =""))
herbiTraits_Master[1:10,1:10]
dim(herbiTraits_Master)
## Remove unneccesary column
herbiTraits_Master = herbiTraits_Master[,which(!(colnames(herbiTraits_Master) %in% c("X", "X.1")))]
#–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––####
##### 4. CORRECT REFERENCES #####
#–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––####
## Select variables with references
variables.with.references = which(grepl(pattern = "Reference", colnames(herbiTraits_Master), fixed = TRUE))
colnames(herbiTraits_Master)[variables.with.references]
# – Make a reference list (short notation) ####
#–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
## Select all variables with References
references = herbiTraits_Master[,variables.with.references]
references = as.vector(as.matrix(references))
## Sources
references = unique(unlist(strsplit(references, split = "; "))) # Number of Sources
length(references) # Number of Sources
references = sort(references)
# references[1:50]
# references[51:100]
# references[101:150]
# references[151:200]
# references[201:250]
# references[251:300]
# references[301:350]
# references[351:400]
# references[401:450]
# references[451:500]
# references[501:550]
# references[551:600]
## Correct Typos and mistakes and make citation style consistent
#––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
herbiTraits_Master$Mass.Reference = gsub(pattern = "All About Birds 2020 Cornell Lab of Ornithology ", replacement = "All About Birds 2020 Cornell Lab of Ornithology", x = herbiTraits_Master$Mass.Reference)
herbiTraits_Master$Diet.Reference = gsub(pattern = "All About Birds 2020 Cornell Lab of Ornithology ", replacement = "All About Birds 2020 Cornell Lab of Ornithology", x = herbiTraits_Master$Diet.Reference)
herbiTraits_Master$Fermentation.Type.Reference = gsub(pattern = "All About Birds 2020 Cornell Lab of Ornithology ", replacement = "All About Birds 2020 Cornell Lab of Ornithology", x = herbiTraits_Master$Fermentation.Type.Reference)
herbiTraits_Master$Limb.Morphology.Reference = gsub(pattern = "All About Birds 2020 Cornell Lab of Ornithology ", replacement = "All About Birds 2020 Cornell Lab of Ornithology", x = herbiTraits_Master$Limb.Morphology.Reference)
herbiTraits_Master$Habitat.Reference = gsub(pattern = "All About Birds 2020 Cornell Lab of Ornithology ", replacement = "All About Birds 2020 Cornell Lab of Ornithology", x = herbiTraits_Master$Habitat.Reference)
herbiTraits_Master$Mass.Reference = gsub(pattern = "Czerwonogora et al. 2011 Neues Jahrbuch f¸r Geologie und Pal‰ontologie-Abhandlungen", replacement = "Czerwonogora et al. 2011 Neues Jahrbuch fur Geologie und Paleontologie-Abhandlungen", x = herbiTraits_Master$Mass.Reference)
herbiTraits_Master$Diet.Reference = gsub(pattern = "Czerwonogora et al. 2011 Neues Jahrbuch f¸r Geologie und Pal‰ontologie-Abhandlungen", replacement = "Czerwonogora et al. 2011 Neues Jahrbuch fur Geologie und Paleontologie-Abhandlungen", x = herbiTraits_Master$Diet.Reference)
herbiTraits_Master$Fermentation.Type.Reference = gsub(pattern = "Czerwonogora et al. 2011 Neues Jahrbuch f¸r Geologie und Pal‰ontologie-Abhandlungen", replacement = "Czerwonogora et al. 2011 Neues Jahrbuch fur Geologie und Paleontologie-Abhandlungen", x = herbiTraits_Master$Fermentation.Type.Reference)
herbiTraits_Master$Limb.Morphology.Reference = gsub(pattern = "Czerwonogora et al. 2011 Neues Jahrbuch f¸r Geologie und Pal‰ontologie-Abhandlungen", replacement = "Czerwonogora et al. 2011 Neues Jahrbuch fur Geologie und Paleontologie-Abhandlungen", x = herbiTraits_Master$Limb.Morphology.Reference)
herbiTraits_Master$Habitat.Reference = gsub(pattern = "Czerwonogora et al. 2011 Neues Jahrbuch f¸r Geologie und Pal‰ontologie-Abhandlungen", replacement = "Czerwonogora et al. 2011 Neues Jahrbuch fur Geologie und Paleontologie-Abhandlungen", x = herbiTraits_Master$Habitat.Reference)
herbiTraits_Master$Mass.Reference = gsub(pattern = "Geist 1998 Stackpole books", replacement = "Geist 1998 Deer of the world: their evolution, behaviour, and ecology", x = herbiTraits_Master$Mass.Reference)
herbiTraits_Master$Diet.Reference = gsub(pattern = "Geist 1998 Stackpole books", replacement = "Geist 1998 Deer of the world: their evolution, behaviour, and ecology", x = herbiTraits_Master$Diet.Reference)
herbiTraits_Master$Fermentation.Type.Reference = gsub(pattern = "Geist 1998 Stackpole books", replacement = "Geist 1998 Deer of the world: their evolution, behaviour, and ecology", x = herbiTraits_Master$Fermentation.Type.Reference)
herbiTraits_Master$Limb.Morphology.Reference = gsub(pattern = "Geist 1998 Stackpole books", replacement = "Geist 1998 Deer of the world: their evolution, behaviour, and ecology", x = herbiTraits_Master$Limb.Morphology.Reference)
herbiTraits_Master$Habitat.Reference = gsub(pattern = "Geist 1998 Stackpole books", replacement = "Geist 1998 Deer of the world: their evolution, behaviour, and ecology", x = herbiTraits_Master$Habitat.Reference)
herbiTraits_Master$Mass.Reference = gsub(pattern = "Gillette and Ray 1981 Smithsonian Institution Press", replacement = "Gillette and Ray 1981 Glyptodonts of North America", x = herbiTraits_Master$Mass.Reference)
herbiTraits_Master$Diet.Reference = gsub(pattern = "Gillette and Ray 1981 Smithsonian Institution Press", replacement = "Gillette and Ray 1981 Glyptodonts of North America", x = herbiTraits_Master$Diet.Reference)
herbiTraits_Master$Fermentation.Type.Reference = gsub(pattern = "Gillette and Ray 1981 Smithsonian Institution Press", replacement = "Gillette and Ray 1981 Glyptodonts of North America", x = herbiTraits_Master$Fermentation.Type.Reference)
herbiTraits_Master$Limb.Morphology.Reference = gsub(pattern = "Gillette and Ray 1981 Smithsonian Institution Press", replacement = "Gillette and Ray 1981 Glyptodonts of North America", x = herbiTraits_Master$Limb.Morphology.Reference)
herbiTraits_Master$Habitat.Reference = gsub(pattern = "Gillette and Ray 1981 Smithsonian Institution Press", replacement = "Gillette and Ray 1981 Glyptodonts of North America", x = herbiTraits_Master$Habitat.Reference)
herbiTraits_Master$Mass.Reference = gsub(pattern = "Kingdon et al. 2013 Mammals of Africa Louys et al. 2011 Journal of Archaeological Science", replacement = "Kingdon et al. 2013 Mammals of Africa; Louys et al. 2011 Journal of Archaeological Science", x = herbiTraits_Master$Mass.Reference)
herbiTraits_Master$Diet.Reference = gsub(pattern = "Kingdon et al. 2013 Mammals of Africa Louys et al. 2011 Journal of Archaeological Science", replacement = "Kingdon et al. 2013 Mammals of Africa; Louys et al. 2011 Journal of Archaeological Science", x = herbiTraits_Master$Diet.Reference)
herbiTraits_Master$Fermentation.Type.Reference = gsub(pattern = "Kingdon et al. 2013 Mammals of Africa Louys et al. 2011 Journal of Archaeological Science", replacement = "Kingdon et al. 2013 Mammals of Africa; Louys et al. 2011 Journal of Archaeological Science", x = herbiTraits_Master$Fermentation.Type.Reference)
herbiTraits_Master$Limb.Morphology.Reference = gsub(pattern = "Kingdon et al. 2013 Mammals of Africa Louys et al. 2011 Journal of Archaeological Science", replacement = "Kingdon et al. 2013 Mammals of Africa; Louys et al. 2011 Journal of Archaeological Science", x = herbiTraits_Master$Limb.Morphology.Reference)
herbiTraits_Master$Habitat.Reference = gsub(pattern = "Kingdon et al. 2013 Mammals of Africa Louys et al. 2011 Journal of Archaeological Science", replacement = "Kingdon et al. 2013 Mammals of Africa; Louys et al. 2011 Journal of Archaeological Science", x = herbiTraits_Master$Habitat.Reference)
herbiTraits_Master$Mass.Reference = gsub(pattern = "Hofreiter et al. 2000 Molecular EcologyGreen 2009 Zoological Journal of the Linnean Society", replacement = "Hofreiter et al. 2000 Molecular Ecology; Green 2009 Zoological Journal of the Linnean Society", x = herbiTraits_Master$Mass.Reference)
herbiTraits_Master$Diet.Reference = gsub(pattern = "Hofreiter et al. 2000 Molecular EcologyGreen 2009 Zoological Journal of the Linnean Society", replacement = "Hofreiter et al. 2000 Molecular Ecology; Green 2009 Zoological Journal of the Linnean Society", x = herbiTraits_Master$Diet.Reference)
herbiTraits_Master$Fermentation.Type.Reference = gsub(pattern = "Hofreiter et al. 2000 Molecular EcologyGreen 2009 Zoological Journal of the Linnean Society", replacement = "Hofreiter et al. 2000 Molecular Ecology; Green 2009 Zoological Journal of the Linnean Society", x = herbiTraits_Master$Fermentation.Type.Reference)
herbiTraits_Master$Limb.Morphology.Reference = gsub(pattern = "Hofreiter et al. 2000 Molecular EcologyGreen 2009 Zoological Journal of the Linnean Society", replacement = "Hofreiter et al. 2000 Molecular Ecology; Green 2009 Zoological Journal of the Linnean Society", x = herbiTraits_Master$Limb.Morphology.Reference)
herbiTraits_Master$Habitat.Reference = gsub(pattern = "Hofreiter et al. 2000 Molecular EcologyGreen 2009 Zoological Journal of the Linnean Society", replacement = "Hofreiter et al. 2000 Molecular Ecology; Green 2009 Zoological Journal of the Linnean Society", x = herbiTraits_Master$Habitat.Reference)
herbiTraits_Master$Mass.Reference = gsub(pattern = "Hollis et al. 1986 Wildlife Research, Osawa 1990 Wildlife Research", replacement = "Hollis et al. 1986 Wildlife Research; Osawa 1990 Wildlife Research", x = herbiTraits_Master$Mass.Reference)
herbiTraits_Master$Diet.Reference = gsub(pattern = "Hollis et al. 1986 Wildlife Research, Osawa 1990 Wildlife Research", replacement = "Hollis et al. 1986 Wildlife Research; Osawa 1990 Wildlife Research", x = herbiTraits_Master$Diet.Reference)
herbiTraits_Master$Fermentation.Type.Reference = gsub(pattern = "Hollis et al. 1986 Wildlife Research, Osawa 1990 Wildlife Research", replacement = "Hollis et al. 1986 Wildlife Research; Osawa 1990 Wildlife Research", x = herbiTraits_Master$Fermentation.Type.Reference)
herbiTraits_Master$Limb.Morphology.Reference = gsub(pattern = "Hollis et al. 1986 Wildlife Research, Osawa 1990 Wildlife Research", replacement = "Hollis et al. 1986 Wildlife Research; Osawa 1990 Wildlife Research", x = herbiTraits_Master$Limb.Morphology.Reference)
herbiTraits_Master$Habitat.Reference = gsub(pattern = "Hollis et al. 1986 Wildlife Research, Osawa 1990 Wildlife Research", replacement = "Hollis et al. 1986 Wildlife Research; Osawa 1990 Wildlife Research", x = herbiTraits_Master$Habitat.Reference)
herbiTraits_Master$Mass.Reference = gsub(pattern = "Syed and Ilyas 2015 Animal Production Science;Bhattacharya et al. 2012 Proceedings of the Zoological Society", replacement = "Syed and Ilyas 2015 Animal Production Science; Bhattacharya et al. 2012 Proceedings of the Zoological Society", x = herbiTraits_Master$Mass.Reference)
herbiTraits_Master$Diet.Reference = gsub(pattern = "Syed and Ilyas 2015 Animal Production Science;Bhattacharya et al. 2012 Proceedings of the Zoological Society", replacement = "Syed and Ilyas 2015 Animal Production Science; Bhattacharya et al. 2012 Proceedings of the Zoological Society", x = herbiTraits_Master$Diet.Reference)
herbiTraits_Master$Fermentation.Type.Reference = gsub(pattern = "Syed and Ilyas 2015 Animal Production Science;Bhattacharya et al. 2012 Proceedings of the Zoological Society", replacement = "Syed and Ilyas 2015 Animal Production Science; Bhattacharya et al. 2012 Proceedings of the Zoological Society", x = herbiTraits_Master$Fermentation.Type.Reference)
herbiTraits_Master$Limb.Morphology.Reference = gsub(pattern = "Syed and Ilyas 2015 Animal Production Science;Bhattacharya et al. 2012 Proceedings of the Zoological Society", replacement = "Syed and Ilyas 2015 Animal Production Science; Bhattacharya et al. 2012 Proceedings of the Zoological Society", x = herbiTraits_Master$Limb.Morphology.Reference)
herbiTraits_Master$Habitat.Reference = gsub(pattern = "Syed and Ilyas 2015 Animal Production Science;Bhattacharya et al. 2012 Proceedings of the Zoological Society", replacement = "Syed and Ilyas 2015 Animal Production Science; Bhattacharya et al. 2012 Proceedings of the Zoological Society", x = herbiTraits_Master$Habitat.Reference)
herbiTraits_Master$Mass.Reference = gsub(pattern = "Wilman et al. 2014 Ecology;Avaliani et al. 2007", replacement = "Wilman et al. 2014 Ecology; Avaliani et al. 2007", x = herbiTraits_Master$Mass.Reference)
herbiTraits_Master$Diet.Reference = gsub(pattern = "Wilman et al. 2014 Ecology;Avaliani et al. 2007", replacement = "Wilman et al. 2014 Ecology; Avaliani et al. 2007", x = herbiTraits_Master$Diet.Reference)
herbiTraits_Master$Fermentation.Type.Reference = gsub(pattern = "Wilman et al. 2014 Ecology;Avaliani et al. 2007", replacement = "Wilman et al. 2014 Ecology; Avaliani et al. 2007", x = herbiTraits_Master$Fermentation.Type.Reference)
herbiTraits_Master$Limb.Morphology.Reference = gsub(pattern = "Wilman et al. 2014 Ecology;Avaliani et al. 2007", replacement = "Wilman et al. 2014 Ecology; Avaliani et al. 2007", x = herbiTraits_Master$Limb.Morphology.Reference)
herbiTraits_Master$Habitat.Reference = gsub(pattern = "Wilman et al. 2014 Ecology;Avaliani et al. 2007", replacement = "Wilman et al. 2014 Ecology; Avaliani et al. 2007", x = herbiTraits_Master$Habitat.Reference)
herbiTraits_Master$Mass.Reference = gsub(pattern = "Madden 2014 Cambridge University Press", replacement = "Madden 2014 Hypsodonty in Mammals: Evolution, Geomorphology, and the Role of Earth System Processes", x = herbiTraits_Master$Mass.Reference)
herbiTraits_Master$Diet.Reference = gsub(pattern = "Madden 2014 Cambridge University Press", replacement = "Madden 2014 Hypsodonty in Mammals: Evolution, Geomorphology, and the Role of Earth System Processes", x = herbiTraits_Master$Diet.Reference)
herbiTraits_Master$Fermentation.Type.Reference = gsub(pattern = "Madden 2014 Cambridge University Press", replacement = "Madden 2014 Hypsodonty in Mammals: Evolution, Geomorphology, and the Role of Earth System Processes", x = herbiTraits_Master$Fermentation.Type.Reference)
herbiTraits_Master$Limb.Morphology.Reference = gsub(pattern = "Madden 2014 Cambridge University Press", replacement = "Madden 2014 Hypsodonty in Mammals: Evolution, Geomorphology, and the Role of Earth System Processes", x = herbiTraits_Master$Limb.Morphology.Reference)
herbiTraits_Master$Habitat.Reference = gsub(pattern = "Madden 2014 Cambridge University Press", replacement = "Madden 2014 Hypsodonty in Mammals: Evolution, Geomorphology, and the Role of Earth System Processes", x = herbiTraits_Master$Habitat.Reference)
herbiTraits_Master$Mass.Reference = gsub(pattern = "NA Lobo 2015 Thesis", replacement = "Lobo 2015 Thesis", x = herbiTraits_Master$Mass.Reference)
herbiTraits_Master$Diet.Reference = gsub(pattern = "NA Lobo 2015 Thesis", replacement = "Lobo 2015 Thesis", x = herbiTraits_Master$Diet.Reference)
herbiTraits_Master$Fermentation.Type.Reference = gsub(pattern = "NA Lobo 2015 Thesis", replacement = "Lobo 2015 Thesis", x = herbiTraits_Master$Fermentation.Type.Reference)
herbiTraits_Master$Limb.Morphology.Reference = gsub(pattern = "NA Lobo 2015 Thesis", replacement = "Lobo 2015 Thesis", x = herbiTraits_Master$Limb.Morphology.Reference)
herbiTraits_Master$Habitat.Reference = gsub(pattern = "NA Lobo 2015 Thesis", replacement = "Lobo 2015 Thesis", x = herbiTraits_Master$Habitat.Reference)
herbiTraits_Master$Mass.Reference = gsub(pattern = "Prideaux 2009 Proceedings of the National Academy of Sciences of the United States of America", replacement = "Prideaux et al. 2009 Proceedings of the National Academy of Sciences of the United States of America", x = herbiTraits_Master$Mass.Reference)
herbiTraits_Master$Diet.Reference = gsub(pattern = "Prideaux 2009 Proceedings of the National Academy of Sciences of the United States of America", replacement = "Prideaux et al. 2009 Proceedings of the National Academy of Sciences of the United States of America", x = herbiTraits_Master$Diet.Reference)
herbiTraits_Master$Fermentation.Type.Reference = gsub(pattern = "Prideaux 2009 Proceedings of the National Academy of Sciences of the United States of America", replacement = "Prideaux et al. 2009 Proceedings of the National Academy of Sciences of the United States of America", x = herbiTraits_Master$Fermentation.Type.Reference)
herbiTraits_Master$Limb.Morphology.Reference = gsub(pattern = "Prideaux 2009 Proceedings of the National Academy of Sciences of the United States of America", replacement = "Prideaux et al. 2009 Proceedings of the National Academy of Sciences of the United States of America", x = herbiTraits_Master$Limb.Morphology.Reference)
herbiTraits_Master$Habitat.Reference = gsub(pattern = "Prideaux 2009 Proceedings of the National Academy of Sciences of the United States of America", replacement = "Prideaux et al. 2009 Proceedings of the National Academy of Sciences of the United States of America", x = herbiTraits_Master$Habitat.Reference)
herbiTraits_Master$Mass.Reference = gsub(pattern = "Torres et al. 2018 Proc B", replacement = "Torres et al. 2018 Proceedings of the Royal Society B", x = herbiTraits_Master$Mass.Reference)
herbiTraits_Master$Diet.Reference = gsub(pattern = "Torres et al. 2018 Proc B", replacement = "Torres et al. 2018 Proceedings of the Royal Society B", x = herbiTraits_Master$Diet.Reference)
herbiTraits_Master$Fermentation.Type.Reference = gsub(pattern = "Torres et al. 2018 Proc B", replacement = "Torres et al. 2018 Proceedings of the Royal Society B", x = herbiTraits_Master$Fermentation.Type.Reference)
herbiTraits_Master$Limb.Morphology.Reference = gsub(pattern = "Torres et al. 2018 Proc B", replacement = "Torres et al. 2018 Proceedings of the Royal Society B", x = herbiTraits_Master$Limb.Morphology.Reference)
herbiTraits_Master$Habitat.Reference = gsub(pattern = "Torres et al. 2018 Proc B", replacement = "Torres et al. 2018 Proceedings of the Royal Society B", x = herbiTraits_Master$Habitat.Reference)
#–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––####
##### 4. SAVE DATA #####
#–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––####
## Create filename
date = as.Date(Sys.time()) # Create Date
date = gsub("-","_",date)
filename = paste("./HerbiTraits_2020_10_01/Changes/3_Output/HerbiTraits_S3_",date,".csv", sep ="") #Create filename
## Save
write.csv(herbiTraits_Master, file = filename, row.names = F)
```{r, include = F}
getwd()
```
# Introduction
HerbiTraits is a functional trait dataset that contains functional traits of all large-bodied (≥10 kg), terrestrial, avian and mammalian herbivores that lived during the last 130,000 years (n = 545 species). The mammalian component of the dataset is based on PHYLACINE V1.2 taxonomy and root traits, but we have provided more detailed trait information for the species of interest. The avian component has been added by the authors of HerbiTraits. HerbiTraits includes data on:
```{r, results = 'hide', include = F}
## Working Directory
getwd()
```
# Introduction
HerbiTraits is a functional trait dataset that contains functional traits of all large-bodied (≥10 kg), terrestrial, avian and mammalian herbivores that lived during the last 130,000 years (n = 545 species). The mammalian component of the dataset is based on PHYLACINE V1.2 taxonomy and root traits, but we have provided more detailed trait information for the species of interest. The avian component has been added by the authors of HerbiTraits. HerbiTraits includes data on:
## Load Data
herbitraits.data = read.csv(xls = "./data/Version_1/HerbiTraits_V1/HerbiTraits_Data_v1.csv")
## Load Data
herbitraits.data = read.csv("./data/Version_1/HerbiTraits_V1/HerbiTraits_Data_v1.csv")
rm(lm())
rm(ls())
rm(list = ls())
## Check Working Directory
getwd()
getwd()
## Check Working Directory
getwd()
## Load Data
herbitraits.data = read.csv("./data/Version_1/HerbiTraits_V1/HerbiTraits_Data_v1.csv")
herbitraits.references = read.csv("./data/Version_1/HerbiTraits_V1/HerbiTraits_References_v1.csv")
View(herbitraits.references)
## Clear Working Memory
rm(list = ls())
## Check Working Directory
getwd()
## Load Data
herbitraits.data = read.csv("./data/Version_1/HerbiTraits_V1/HerbiTraits_Data_v1.csv")
herbitraits.references = read.csv("./data/Version_1/HerbiTraits_V1/HerbiTraits_References_v1.csv")
`r nrow(herbitraits.data)`
## Clear Working Memory
rm(list = ls())
## Check Working Directory
getwd()
## Load Data
herbitraits.data = read.csv("./data/Version_1/HerbiTraits_V1/HerbiTraits_Data_v1.csv")
herbitraits.references = read.csv("./data/Version_1/HerbiTraits_V1/HerbiTraits_References_v1.csv")
## Working Directory
getwd()
path <- "./Version_Dev/HerbiTraits_Dev/"
merge_file_name <- "./Version_Dev/HerbiTraits_Dev//merged_file.xlsx"
list.files(path= path, full.names=TRUE)
## Working Directory
getwd()
path <- "./Data/Version_Dev/HerbiTraits_Dev/"
list.files(path= path, full.names=TRUE)
filenames_list <- list.files(path= path, full.names=TRUE)
merge_file_name <- "./Data/Version_Dev/HerbiTraits_Dev//merged_file.xlsx"
All <- lapply(filenames_list,function(filename){
print(paste("Merging",filename,sep = " "))
read.xlsx(filename)
})
## Load Libraries
library(openxlsx) # Necessary to create Excel file
All <- lapply(filenames_list,function(filename){
print(paste("Merging",filename,sep = " "))
read.xlsx(filename)
})
## Clear Working Memory
rm(list = ls()) # clean memory
graphics.off() # close graphic windows
## Working Directory
getwd()
## Load Libraries
library(openxlsx) # Necessary to create Excel file
path <- "./Data/Version_Dev/HerbiTraits_Dev/" # File path
merge_file_name <- "./Data/Version_Dev/HerbiTraits_Dev//merged_file.xlsx" #Name of the final excel file
filenames_list <- list.files(path= path, full.names=TRUE) # list files in folder
All <- lapply(filenames_list,function(filename){
print(paste("Merging",filename,sep = " "))
read.xlsx(filename)
})
filename
All <- lapply(filenames_list,function(filename){
print(paste("Merging",filename,sep = " "))
read.xlsx(filename)
})
df <- do.call(rbind.data.frame, All)
library(data.table) ## for fast fread() function
library(XLConnect)
install.packages("XLConnect")
install.packages("data.table")
# install.packages("XLConnect")
library(XLConnect)
merge_file_name <- "./Data/Version_Dev/HerbiTraits_Dev/merged_file.xlsx" #Name of the final excel file
filenames_list <- list.files(path= path, full.names=TRUE) # list files in folder
All <- lapply(filenames_list,function(filename){
print(paste("Merging",filename,sep = " "))
read.xlsx(filename)
})
folder <- "./Data/Version_Dev/HerbiTraits_Dev/"
f.out <- "./Data/Version_Dev/HerbiTraits_Dev/merged_file.xlsx"
## load in file
wb <- loadWorkbook(f.out, create=TRUE)
wb = createWorkbook()
?createWorkbook
## Clear Working Memory
rm(list = ls()) # clean memory
graphics.off() # close graphic windows
path <- "sample-data/merge-files/xlsx"
merge_file_name <- "sample-data/merge-files//merged_file.xlsx"
filenames_list <- list.files(path= path, full.names=TRUE)
path <- "./Data/Version_Dev/HerbiTraits_Dev/" # File path
merge_file_name <- "./Data/Version_Dev/HerbiTraits_Dev/merged_file.xlsx" #Name of the final excel file
filenames_list <- list.files(path= path, full.names=TRUE)
filenames_list
path <- "./Data/Version_Dev/HerbiTraits_Dev" # File path
merge_file_name <- "./Data/Version_Dev/HerbiTraits_Dev/merged_file.xlsx" #Name of the final excel file
filenames_list <- list.files(path= path, full.names=TRUE)
filenames_list
All <- lapply(filenames_list,function(filename){
print(paste("Merging",filename,sep = " "))
read.csv(filename)
})
df <- do.call(rbind.data.frame, All)
View(All)
lapply(filenames_list,read.csv(filename)
## Clear Working Memory
rm(list = ls()) # clean memory
graphics.off() # close graphic windows
## Clear Working Memory
rm(list = ls()) # clean memory
graphics.off() # close graphic windows
path <- "./Data/Version_Dev/HerbiTraits_Dev" # File path
merge_file_name <- "./Data/Version_Dev/HerbiTraits_Dev/merged_file.xlsx" #Name of the final excel file
filenames_list <- list.files(path= path, full.names=TRUE)
All <- lapply(filenames_list,read.csv(filename))
All <- lapply(filenames_list,read.csv(filename){
print(paste("Merging",filename,sep = " "))
read.csv(filename)
})
All <- lapply(filenames_list,read.csv(filename){
print(paste("Merging",filename,sep = " "))
read.csv(filename)
})
path <- "./Data/Version_Dev/HerbiTraits_Dev" # File path
merge_file_name <- "./Data/Version_Dev/HerbiTraits_Dev/merged_file.xlsx" #Name of the final excel file
filenames_list <- list.files(path= path, full.names=TRUE)
All <- lapply(filenames_list,read.csv(filename){
print(paste("Merging",filename,sep = " "))
read.csv(filename)
})
## Clear Working Memory
rm(list = ls()) # clean memory
graphics.off() # close graphic windows
path <- "./Data/Version_Dev/HerbiTraits_Dev" # File path
merge_file_name <- "./Data/Version_Dev/HerbiTraits_Dev/merged_file.xlsx" #Name of the final excel file
filenames_list <- list.files(path= path, full.names=TRUE)
All <- lapply(filenames_list,read.csv(filename){
print(paste("Merging",filename,sep = " "))
read.csv(filename)
})
All <- lapply(filenames_list,function(filename){
print(paste("Merging",filename,sep = " "))
read.csv(filename)
})
str(All)
df <- do.call(rbind.data.frame, All)
All[1]
filenames_list
grepl("_Data", filenames_list)
which(grepl("_Data", filenames_list))
filenames_list[which(grepl("_Data", filenames_list))]
read.csv(filenames_list[which(grepl("_Data", filenames_list))])
HerbiTraits_Data = read.csv(filenames_list[which(grepl("_Data", filenames_list))])
HerbiTraits_Data = read.csv(filenames_list[which(grepl("_Data", filenames_list))])
HerbiTraits_Metadata = read.csv(filenames_list[which(grepl("_Metadata", filenames_list))])
HerbiTraits_References = read.csv(filenames_list[which(grepl("_References", filenames_list))])
wb = createWorkbook()
sheet = createSheet(wb, "Sheet 1")
sheet = createSheet(wb, "Sheet 1")
library("openxlsx")
sheet = createSheet(wb, "Sheet 1")
wb = createWorkbook()
sheet = createSheet(wb, "Sheet 1")
?createSheet
library("xlsx")
install.packages('xlsx')
library("xlsx")
sheet = createSheet(wb, "Sheet 1")
?write.xlsx
library("openxlsx")
write.xlsx(HerbiTraits_Data, file="HerbiTraits_Dev.xlsx", sheetName="sheet1", row.names=FALSE)
write.xlsx(HerbiTraits_Metadata, file="HerbiTraits_Dev.xlsx", sheetName="sheet2", append=TRUE, row.names=FALSE)
write.xlsx(HerbiTraits_References, file="HerbiTraits_Dev.xlsx", sheetName="sheet2", append=TRUE, row.names=FALSE)
write.xlsx(HerbiTraits_Data, file="HerbiTraits_Dev.xlsx", sheetName="sheet1", row.names=FALSE)
getwd()
write.xlsx(HerbiTraits_Data, file="./Data/Version_Dev/HerbiTraits_Dev/HerbiTraits_Dev.xlsx", sheetName="sheet1", row.names=FALSE)
write.xlsx(HerbiTraits_Metadata, file="./Data/Version_Dev/HerbiTraits_Dev/HerbiTraits_Dev.xlsx", sheetName="sheet2", append=TRUE, row.names=FALSE)
write.xlsx(HerbiTraits_References, file="./Data/Version_Dev/HerbiTraits_Dev/HerbiTraits_Dev.xlsx", sheetName="sheet2", append=TRUE, row.names=FALSE)
## Clear Working Memory
rm(list = ls()) # clean memory
graphics.off() # close graphic windows
# Create File Paths
path <- "./Data/Version_Dev/HerbiTraits_Dev" # File path
filenames_list <- list.files(path= path, full.names=TRUE) # List of all files in the folder
## Load CSV files
HerbiTraits_Data = read.csv(filenames_list[which(grepl("_Data", filenames_list))])
HerbiTraits_Metadata = read.csv(filenames_list[which(grepl("_Metadata", filenames_list))])
HerbiTraits_References = read.csv(filenames_list[which(grepl("_References", filenames_list))])
write.xlsx(HerbiTraits_Metadata, file="./Data/Version_Dev/HerbiTraits_Dev/HerbiTraits_Dev.xlsx", sheetName="sheet1", row.names=FALSE)
write.xlsx(HerbiTraits_Data, file="./Data/Version_Dev/HerbiTraits_Dev/HerbiTraits_Dev.xlsx", sheetName="sheet2",append=TRUE, row.names=FALSE)
write.xlsx(HerbiTraits_References, file="./Data/Version_Dev/HerbiTraits_Dev/HerbiTraits_Dev.xlsx", sheetName="sheet3", append=TRUE, row.names=FALSE)
write.xlsx(HerbiTraits_Metadata, file="./Data/Version_Dev/HerbiTraits_Dev/HerbiTraits_Dev.xlsx", sheetName="sheet1", row.names=FALSE)
write.xlsx(HerbiTraits_Metadata, file="./Data/Version_Dev/HerbiTraits_Dev/HerbiTraits_Dev.xlsx", sheetName="sheet1", row.names=FALSE)
write.xlsx(HerbiTraits_Data, file="./Data/Version_Dev/HerbiTraits_Dev/HerbiTraits_Dev.xlsx", sheetName="sheet2",append=TRUE, row.names=FALSE)
?write.xlsx
write.xlsx(HerbiTraits_Metadata, file="./Data/Version_Dev/HerbiTraits_Dev/HerbiTraits_Dev.xlsx", sheetName="Metadata", row.names=FALSE)
library("openxlsx")
# Create a blank workbook
OUT <- createWorkbook()
# Add some sheets to the workbook
addWorksheet(OUT, "Sheet 1 Name")
addWorksheet(OUT, "Sheet 2 Name")
# Write the data to the sheets
writeData(OUT, sheet = "Sheet 1 Name", x = HerbiTraits_Metadata)
writeData(OUT, sheet = "Sheet 2 Name", x = HerbiTraits_Data)
# Export the file
saveWorkbook(OUT, "My output file.xlsx")
# install.packages("data.table")
#install.packages('openxlsx')
library("openxlsx")
# Create File Paths
path <- "./Data/Version_Dev/HerbiTraits_Dev" # File path
filenames_list <- list.files(path= path, full.names=TRUE) # List of all files in the folder
## Load CSV files
HerbiTraits_Data = read.csv(filenames_list[which(grepl("_Data", filenames_list))])
HerbiTraits_Metadata = read.csv(filenames_list[which(grepl("_Metadata", filenames_list))])
HerbiTraits_References = read.csv(filenames_list[which(grepl("_References", filenames_list))])
## Add sheets to the workbook
addWorksheet(OUT, "MetaData")
addWorksheet(OUT, "Data")
######################################################################!
# #
# S999: Create Excel File #
# #
######################################################################!
# Explanation: This files takes the three CSV files (HerbiTraits_Metadata, HerbiTraits_Data, HerbiTraits_References) and combines them into an excel file.
# Output: An Excel file named "HerbiTraits_vX"
# Duration:
# Status: finished (2020/11/25)
#–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
## Clear Working Memory
rm(list = ls()) # clean memory
graphics.off() # close graphic windows
## Working Directory
getwd()
## Load Libraries
#install.packages('openxlsx')
library("openxlsx")
# Create File Paths
path <- "./Data/Version_Dev/HerbiTraits_Dev" # File path
filenames_list <- list.files(path= path, full.names=TRUE) # List of all files in the folder
## Load CSV files
HerbiTraits_Data = read.csv(filenames_list[which(grepl("_Data", filenames_list))])
HerbiTraits_Metadata = read.csv(filenames_list[which(grepl("_Metadata", filenames_list))])
HerbiTraits_References = read.csv(filenames_list[which(grepl("_References", filenames_list))])
## Create a blank workbook
OUT <- createWorkbook()
## Add sheets to the workbook
addWorksheet(OUT, "MetaData")
addWorksheet(OUT, "Data")
addWorksheet(OUT, "References")
## Write the data to the sheets
writeData(OUT, sheet = "MetaData", x = HerbiTraits_Metadata)
writeData(OUT, sheet = "Data", x = HerbiTraits_Data)
writeData(OUT, sheet = "References", x = HerbiTraits_References)
## Export the file
saveWorkbook(OUT, "/Data/Version_Dev/HerbiTraits_Dev/HerbiTraits_Dev.xlsx")
## Clear Working Memory
rm(list = ls()) # clean memory
graphics.off() # close graphic windows
## Working Directory
getwd()
## Load Libraries
#install.packages('openxlsx')
library("openxlsx")
# Create File Paths
path <- "./Data/Version_Dev/HerbiTraits_Dev" # File path
filenames_list <- list.files(path= path, full.names=TRUE) # List of all files in the folder
## Load CSV files
HerbiTraits_Data = read.csv(filenames_list[which(grepl("_Data", filenames_list))])
HerbiTraits_Metadata = read.csv(filenames_list[which(grepl("_Metadata", filenames_list))])
HerbiTraits_References = read.csv(filenames_list[which(grepl("_References", filenames_list))])
## Create a blank workbook
OUT <- createWorkbook()
## Add sheets to the workbook
addWorksheet(OUT, "MetaData")
addWorksheet(OUT, "Data")
addWorksheet(OUT, "References")
## Write the data to the sheets
writeData(OUT, sheet = "MetaData", x = HerbiTraits_Metadata)
writeData(OUT, sheet = "Data", x = HerbiTraits_Data)
writeData(OUT, sheet = "References", x = HerbiTraits_References)
## Export the file
saveWorkbook(OUT, "/Data/Version_Dev/HerbiTraits_Dev/HerbiTraits_Dev.xlsx")
## Export the file
saveWorkbook(OUT, "./Data/Version_Dev/HerbiTraits_Dev/HerbiTraits_Dev.xlsx")
## Clear Working Memory
rm(list = ls())
## Check Working Directory
getwd()
## Load Data
herbitraits.data = read.csv("./data/Version_1/HerbiTraits_V1/HerbiTraits_Data_v1.csv")
herbitraits.references = read.csv("./data/Version_1/HerbiTraits_V1/HerbiTraits_References_v1.csv")
r format(Sys.time(), '%d %B %Y')
getwd()
getwd()
## Load Data
herbitraits.data = read.csv("./Data/Version_1/HerbiTraits_V1/HerbiTraits_Data_v1.csv")
## Load Data
herbitraits.data = read.csv("./Data/Version_1/HerbiTraits_V1/HerbiTraits_Data_v1.csv")
## Load Data
herbitraits.data = read.csv("../Data/Version_1/HerbiTraits_V1/HerbiTraits_Data_v1.csv")
## Load Data
herbitraits.data = read.csv("./Data/Version_1/HerbiTraits_V1/HerbiTraits_Data_v1.csv")
getwd()
/Users/au572919/Research/I_MegaPast2Future/HerbiTraits/Data/Version_1/HerbiTraits_V1/HerbiTraits_Data_v1.csv"
"Users/au572919/Research/I_MegaPast2Future/HerbiTraits/Data/Version_1/HerbiTraits_V1/HerbiTraits_Data_v1.csv"
read.csv("Users/au572919/Research/I_MegaPast2Future/HerbiTraits/Data/Version_1/HerbiTraits_V1/HerbiTraits_Data_v1.csv")
read.csv("Users/au572919/Research/I_MegaPast2Future/HerbiTraits/Data/Version_1/HerbiTraits_V1/HerbiTraits_Data_v1.csv")
file.exists("Users/au572919/Research/I_MegaPast2Future/HerbiTraits/Data/Version_1/HerbiTraits_V1/HerbiTraits_Data_v1.csv")
## Load Data
herbitraits.data = read.csv("./data/Version_1/HerbiTraits_V1/HerbiTraits_Data_v1.csv")
## Check Working Directory
getwd()
getwd()
## Check Working Directory
getwd()
setwd("/Users/au572919/Research/I_MegaPast2Future/HerbiTraits")
## Load Data
herbitraits.data = read.csv("./Data/Version_1/HerbiTraits_V1/HerbiTraits_Data_v1.csv")
## Check Working Directory
getwd()
setwd("/Users/au572919/Research/I_MegaPast2Future/HerbiTraits")
## Load Data
herbitraits.data = read.csv("./Data/Version_1/HerbiTraits_V1/HerbiTraits_Data_v1.csv")
## Clear Working Memory
rm(list = ls())
## Check Working Directory
getwd()
setwd("/Users/au572919/Research/I_MegaPast2Future/HerbiTraits")
## Load Data
herbitraits.data = read.csv("./Data/Version_1/HerbiTraits_V1/HerbiTraits_Data_v1.csv")
herbitraits.references = read.csv("./Data/Version_1/HerbiTraits_V1/HerbiTraits_References_v1.csv")
## Clear Working Memory
rm(list = ls())
## Check Working Directory
getwd()
setwd("/Users/au572919/Research/I_MegaPast2Future/HerbiTraits") # Change Directiory if needed
## Load Data
herbitraits.data = read.csv("./Data/Version_1/HerbiTraits_V1/HerbiTraits_Data_v1.csv")
herbitraits.references = read.csv("./Data/Version_1/HerbiTraits_V1/HerbiTraits_References_v1.csv")