Skip to content

Commit c03bfd1

Browse files
committed
update species key for a few manual corrections
and helper functions; related to #1 @bselden and @JWMorley you might want to be aware of how I did this, and how it differs slightly from the video I link in Issue #1. Basically what I changed is something I already pointed out in the video: I wrote a function to avoid introducing inconsistencies.
1 parent dc813fc commit c03bfd1

File tree

3 files changed

+6191
-6016
lines changed

3 files changed

+6191
-6016
lines changed

R/create.spp.key.R

Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,181 @@ create.spp.key <- function(spp, taxInfo, spp.corr1){
111111

112112

113113

114+
# ======================
115+
# = Manual Corrections =
116+
# ======================
117+
# noticed in GMEX
118+
# match.badSpp <- function(x, value=FALSE){
119+
#
120+
# ux <- unique(x)
121+
# badEgg <- grepl("[eE][gG]{2}", ux)
122+
# badFish <- grepl("(?<![a-z])fish(?![a-z])", ux, ignore.case=TRUE, perl=TRUE)
123+
# badLarv <- grepl("(?<![a-z])larv(a[e])?(?![a-z])", ux, ignore.case=TRUE, perl=TRUE)
124+
# badYoy <- grepl("(?<![a-z])yoy(?![a-z])", ux, ignore.case=TRUE, perl=TRUE)
125+
# missSpp <- ux=="" | is.na(ux)
126+
# bad.x <- ux[(badEgg | badFish | badLarv | badYoy | missSpp)]
127+
# bad.i <- (x%in%bad.x)
128+
# if(value){
129+
# return(x[bad.i])
130+
# }else{
131+
# return(bad.i)
132+
# }
133+
#
134+
# }
135+
# badSpp <- X[,match.badSpp(ref)]
136+
# noID <- X[,spp=="" | is.na(spp)]
137+
# dput(X[!badSpp&!noID&taxLvl!="species"&!is.na(taxLvl)&is.species(spp)&is.na(common),unique(spp)])
138+
# c("Astrea Orbicella", "Bathynectes superba", "Centropristes ocyurus", "Glyphocrangon aculeata", "Lycoteuthis diadema", "Moira atropus", "Mustellus canis", "Phenacoscorpius nebris", "Synagrops bella", "Synagrops microlepis")
139+
# Function to see if the corrected version of a bad spp name
140+
# already exists in a data set; if it does,
141+
# then the wrong version is overwritten with the content
142+
check.and.set <- function(wrong, corrected){
143+
check <- spp.key[,corrected%in%spp]
144+
if(check){
145+
# if the corrected name already exists,
146+
# make sure to have all the rows with the wrong name match up with the corrected rows,
147+
# that way if we make any changes, both sets get updated
148+
# For example, if a name XX is wrong, and Xx is the corrected name,
149+
# say that we are going to set the trophic level of Xx to 42,
150+
# but the current entry is 40. If we were to say 'change all rows
151+
# with name XX to have a TL to 42, and also switch the bad XX name to the good Xx name',
152+
# then we would have some rows with TL of 42 (the ones that originally had the bad name), and
153+
# some rows with TL of 40 (the ones that originally had the corrected name).
154+
# Thus, we have to get the names and other content to match before changing anything.
155+
# Bottom line is that we need to be sure that all things are consistent, and that this requires
156+
# more care when we are switching the 'spp' of an entry to a 'spp' that is already there.
157+
#
158+
# stopifnot(all(sapply(spp.key[spp==corrected], function(x)length(unique(x[!is.na(x)]))<=1))) # this check is to ensure that the contents of the corrected data set do not contain conflicts (NA's aside, which may or may not be a good idea)
159+
stopifnot(all(sapply(spp.key[spp==corrected], function(x)length(unique(x))<=1)))
160+
noSet <- c("ref")
161+
all.but.noSet <- names(spp.key)[names(spp.key)!=noSet]
162+
spp.key[spp==wrong, c(all.but.noSet):=spp.key[spp==corrected,eval(s2c(all.but.noSet))]]
163+
}else{
164+
# if the corrected name doesn't already exist,
165+
# then simply switch the wrong name to the corrected name,
166+
spp.key[spp==wrong, spp:=corrected]
167+
}
168+
}
169+
170+
check.and.set(wrong="Moira atropus", corrected="Moira atropos")
171+
spp.key[spp=="Moira atropos",
172+
':='(
173+
taxLvl="species",
174+
species="Moira atropos",
175+
genus="Moira",
176+
website="http://www.marinespecies.org/echinoidea/aphia.php?p=taxdetails&id=158067"
177+
)
178+
]
179+
180+
# spp.key[spp=="Astrea Orbicella", # couldn't find this one
181+
# ]
182+
183+
check.and.set(wrong="Bathynectes superba", corrected="Bathynectes maravigna")
184+
spp.key[spp=="Bathynectes maravigna",
185+
':='(
186+
taxLvl="species",
187+
species="Bathynectes maravigna",
188+
genus="Bathynectes",
189+
website="http://www.marinespecies.org/aphia.php?p=taxdetails&id=107377"
190+
191+
)
192+
]
193+
194+
check.and.set(wrong="Centropristes ocyurus", corrected="Centropristis ocyurus")
195+
spp.key[spp=="Centropristis ocyurus",
196+
':='(
197+
taxLvl="species",
198+
species="Centropristis ocyurus",
199+
genus="Centropristis",
200+
common="Bank sea bass",
201+
Picture="y",
202+
trophicLevel=3.5,
203+
trophicLevel.se=0.53,
204+
website="http://www.fishbase.org/summary/3316"
205+
)
206+
]
207+
208+
check.and.set(wrong="Glyphocrangon aculeata", corrected="Glyphocrangon aculeata")
209+
spp.key[spp=="Glyphocrangon aculeata",
210+
':='(
211+
taxLvl="species",
212+
species="Glyphocrangon aculeata",
213+
genus="Glyphocrangon",
214+
website="http://www.marinespecies.org/aphia.php?p=taxdetails&id=421812"
215+
216+
)
217+
]
218+
219+
check.and.set(wrong="Lycoteuthis diadema", corrected="Lycoteuthis lorigera")
220+
spp.key[spp=="Lycoteuthis lorigera",
221+
':='(
222+
taxLvl="species",
223+
species="Lycoteuthis lorigera",
224+
genus="Lycoteuthis",
225+
website="http://www.marinespecies.org/aphia.php?p=taxdetails&id=342361"
226+
227+
)
228+
]
229+
230+
# found a fix for Mustellus canis (only 1 l), but new information tells we
231+
# that we already have the correct name somewhere, so I have to fix then update both
232+
# spp.key[spp=="Mustelus canis"]
233+
234+
check.and.set(wrong="Mustellus canis", corrected="Mustelus canis")
235+
spp.key[spp=="Mustelus canis",
236+
':='(
237+
taxLvl="species",
238+
common="Dusky smooth-hound",
239+
Picture="y",
240+
trophicLevel=3.6,
241+
# trophicLevel.se=0.2,
242+
website="http://www.fishbase.org/summary/Mustelus-canis.html"
243+
)
244+
]
245+
246+
check.and.set(wrong="Phenacoscorpius nebris", corrected="Phenacoscorpius nebris")
247+
spp.key[spp=="Phenacoscorpius nebris",
248+
':='(
249+
taxLvl="species",
250+
species="Phenacoscorpius nebris",
251+
genus="Phenacoscorpius",
252+
common="Short-tube scorpionfish",
253+
Picture="y",
254+
trophicLevel=3.5,
255+
trophicLevel.se=0.6,
256+
website="http://www.fishbase.org/summary/12454"
257+
)
258+
]
259+
260+
261+
262+
spp.key[spp=="Synagrops bellus",
263+
':='(
264+
taxLvl="species",
265+
species="Synagrops bellus",
266+
genus="Synagrops",
267+
website="http://www.marinespecies.org/aphia.php?p=taxdetails&id=159584"
268+
)
269+
]
270+
271+
272+
spp.key[spp=="Synagrops microlepis",
273+
':='(
274+
taxLvl="species",
275+
species="Synagrops microlepis",
276+
genus="Synagrops",
277+
common="Thinlip splitfin",
278+
Picture="y",
279+
trophicLevel=3.2,
280+
trophicLevel.se=0.37,
281+
website="http://www.fishbase.org/summary/5059"
282+
283+
)
284+
]
285+
286+
287+
288+
114289

115290
# spp.key[!is.na(spp) & !is.na(species) & taxLvl=="species"] # these are probably the good ones
116291

data/spp.key.RData

15.4 KB
Binary file not shown.

0 commit comments

Comments
 (0)