File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -54,6 +54,11 @@ get_trophic_level <- function(lookupTable) {
5454 server = " fishbase"
5555 ) | >
5656 dplyr :: select(DietTroph , FoodTroph )
57+ if (nrow(vertibrates ) == 0 ) {
58+ # if no data
59+ # set DietTroph, FoodTroph to NA
60+ vertibrates <- data.frame (DietTroph = NA , FoodTroph = NA )
61+ }
5762 # estimate table.
5863 est <- rfishbase :: estimate(
5964 species_list = speciesNm ,
@@ -144,13 +149,16 @@ get_trophic_level <- function(lookupTable) {
144149 ) | >
145150 dplyr :: select(Troph )
146151
147- vertibrates <- cbind(vertibrates , est )
148-
149- if (any(! is.na(vertibrates ))) {
150- vertibrates <- data.frame (as.list(colMeans(vertibrates , na.rm = T )))
151- fishbaseTable $ DietTroph [isp ] <- vertibrates $ DietTroph
152- fishbaseTable $ FoodTroph [isp ] <- vertibrates $ FoodTroph
153- fishbaseTable $ EstTroph [isp ] <- vertibrates $ FoodTroph
152+ if (any(! is.na(vertibrates )) | any(! is.na(est ))) {
153+ fishbaseTable $ DietTroph [isp ] <- mean(
154+ vertibrates $ DietTroph ,
155+ na.rm = TRUE
156+ )
157+ fishbaseTable $ FoodTroph [isp ] <- mean(
158+ vertibrates $ FoodTroph ,
159+ na.rm = TRUE
160+ )
161+ fishbaseTable $ EstTroph [isp ] <- mean(est $ FoodTroph , na.rm = TRUE )
154162 fishbaseTable $ vertibrate [isp ] <- TRUE
155163 } else {
156164 # inverts
You can’t perform that action at this time.
0 commit comments