-
Notifications
You must be signed in to change notification settings - Fork 0
/
jatun_sacha_manu_rresults.txt
57 lines (37 loc) · 2.04 KB
/
jatun_sacha_manu_rresults.txt
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
> ### Read external commands
> library(shipunov)
package 'shipunov', version 1.3-1
> ### Read input tables
> ## "as.is=TRUE" is to avoid conversion into factors
> ## Main table (species list), serves also as feature (images) table:
> pics <- read.table("_sp_pics.txt", h=TRUE, sep="\t", as.is=TRUE)
> ## Other feature tables:
> auth <- read.table("_sp_auth.txt", sep="\t", as.is=TRUE, quote="") # need "quote" because some author names might contain quote-like symbols
> fam <- read.table("_gen_fam.txt", sep="\t", as.is=TRUE)
> ## Filter tables
> alt <- read.table("_fam_alt.txt", sep="\t", as.is=TRUE)
> ### Make species names and start the main output table
> SPEC <- pics[, 1]
> AUTH <- Recode4(SPEC, auth[, 1], auth[, 2])
> write(SPEC[AUTH == ""], file="0no_sp_auth.txt") # diagnostics!
> AUTH <- gsub("&", "\\\\&", AUTH) # because ampersand is the special symbol in TeX
> JS <- data.frame(SPEC=paste0("\\SP{", paste0("\\KK{", SPEC, "}"), " ", AUTH, "}"))
> ### Make links to images
> ## There could be > 1 image per species so:
> IMG0 <- aggregate(pics[, 2], list(pics[, 1]), function(.x) paste0("\\I{", .x, "}", collapse=" "))
> IMG1 <- Recode4(SPEC, IMG0[, 1], IMG0[, 2])
> write(JS$SPEC[IMG1 == ""], file="0no_pics.txt") # diagnostics!
> JS$IMG <- paste0("\\II{", IMG1, "}")
> ### Make genera
> GEN <- do.call(rbind, strsplit(SPEC, " "))[, 1] # outputs matrix, we need the first column with genus name
> ### Make names of higher categories (here families) and immediately convert it from alternative to traditional
> JS$FAM <- Recode(Recode4(GEN, fam[, 1], fam[, 2]), alt[, 1], alt[, 2])
> write(JS$SPEC[JS$FAM == ""], file="0no_fam.txt") # diagnostics!
> JS <- JS[order(JS$FAM, JS$SPEC), ]
> ## We need these names only on the first occurrence:
> ##FAM1 <- JS$FAM
> ##FAM2 <- c(tail(FAM1, 1), head(FAM1, -1))
> JS$FAM <- ifelse(Ditto(JS$FAM) == "", paste0("\\FF{", "Family ", "\\KK{", JS$FAM, "}}"), "")
> ### Make the output table
> write.table(file="0body", JS[, c("FAM", "SPEC", "IMG")], quote=FALSE,
+ row.names=FALSE, col.names=FALSE, sep=" ", eol="\n\n")