I have an if else statement in an R script.The problem is based on the if condition,the control always goes to the else statement and executes it whereas the control should have stopped before based on the condition satisfaction and executed instead of always going to the else statement and executing it which is actually wrong.
getwd()
setwd("C:/Users/Ritwik/Documents/R/Files")
fl <- list.files("C:/Users/Ritwik/Documents/R/Files",
pattern = "*.csv",
full.names = TRUE)
fl
basename(fl)
fi<-basename(fl)
if(fi %in% 'Unisim'){
source("C:/Users/Ritwik/Documents/R/Unisim_Shiny_App.R")$value
} else if(fi %in% 'Aspen_China'){
source("C:/Users/Ritwik/Documents/R/Aspen_China_Shiny_App.R")$value
} else if(fi %in% 'Aspen_Munich'){
source("C:/Users/Ritwik/Documents/R/Aspen_Munich_Shiny_App.R")$value
} else if(fi %in% 'Promax') {
source("C:/Users/Ritwik/Documents/R/Promax_Shiny_App.R")$value
} else {
source("C:/Users/Ritwik/Documents/R/OLI_Shiny_App.R")$value
}
Promax_Jan_Sept_2020_Data.csv file is present in the path mentioned in the script from where it picks up csv file based on pattern match before the if else condition.So ideally,based on the if else condition it should execute promax script based on the input file but it goes to the else statement and executes the OLI script.So what happens is it always goes to the else statement and executes the same irrespective of the conditions.