I have created a function futureHighs which creates a named list with the average temperature in each scenario. I want to modify the function so that it returns a useful error message if the city is not in the dataset.
futureHighs <- function(ex, city){
if missing(city=="Ankara"){ stop("Ankara is not in dataset")
}else
p <- ex %>%
filter(year>=2080&year<=2100) %>%
filter(scenario=="RCP2.6") %>%
filter(city=="Ankara")
HighTemp2.6 = mean(p$txx)
s <- ex %>%
filter(year>=2080&year<=2100) %>%
filter(scenario=="RCP8.5") %>%
filter(city=="Ankara")
HighTemp8.5 = mean(s$txx)
list(HighTemp2.6, HighTemp8.5)
}
I have tried this but it doesn't return an error even if I change the city name to something random. Feel like I'm doing something wrong with the ifelse or the missing function. Any help appreciated. Thanks