Skip to content

Commit fea3946

Browse files
committed
fix(concat): issues concatenating objects with different number of rows. Removed the need for this
1 parent e45796a commit fea3946

1 file changed

Lines changed: 15 additions & 7 deletions

File tree

R/get_trophic_level.R

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)