match.arg(method) Error : stop("'arg' must be NULL or a character vector")

I'm currently building a business calculator for my company, but it seems not to work...
Here is my code :

FGEN<-function(var1){
for (i in 1:length(FRANCH)){
  FFGEN[i]<-if(var1[i]%in%c("CHOS020","CHOS025","CRES010")==FALSE){
    if(FRANCH[i]==0){
      FFGEN[i]<-as.numeric(filter(KTE_GI,KTE_GI$B_COEFF=="C_FRANCHISE",KTE_GI$B_PARAMC2=="0",KTE_GI$B_PARAMC3=="****")[,12])
    }else if(FRANCH[i]==18){
      FFGEN[i]<-as.numeric(filter(KTE_GI,KTE_GI$B_COEFF=="C_FRANCHISE",KTE_GI$B_PARAMC2=="18",KTE_GI$B_PARAMC3=="****")[,12])
    }else if(FRANCH[i]==27){
      FFGEN[i]<-as.numeric(filter(KTE_GI,KTE_GI$B_COEFF=="C_FRANCHISE",KTE_GI$B_PARAMC2=="27",KTE_GI$B_PARAMC3=="****")[,12])
    }else if(FRANCH[i]==36){
      FFGEN[i]<-as.numeric(filter(KTE_GI,KTE_GI$B_COEFF=="C_FRANCHISE",KTE_GI$B_PARAMC2=="36",KTE_GI$B_PARAMC3=="****")[,12])
    }else if(FRANCH[i]==55){
      FFGEN[i]<-as.numeric(filter(KTE_GI,KTE_GI$B_COEFF=="C_FRANCHISE",KTE_GI$B_PARAMC2=="55",KTE_GI$B_PARAMC3=="****")[,12])
    }else if(FRANCH[i]==72){
      FFGEN[i]<-as.numeric(filter(KTE_GI,KTE_GI$B_COEFF=="C_FRANCHISE",KTE_GI$B_PARAMC2=="72",KTE_GI$B_PARAMC3=="****")[,12])
    }else if(FRANCH[i]==91){
      FFGEN[i]<-as.numeric(filter(KTE_GI,KTE_GI$B_COEFF=="C_FRANCHISE",KTE_GI$B_PARAMC2=="91",KTE_GI$B_PARAMC3=="****")[,12])
    }else{
      FFGEN[i]<-1
    }
  }else if(var1[i]%in%c("CHOS020","CHOS025","CRES010")==TRUE){
    if(FRANCH[i]==0){
      FFGEN[i]<-as.numeric(filter(KTE_GI,KTE_GI$B_COEFF=="C_FRANCHISE",KTE_GI$B_PARAMC2=="0",KTE_GI$B_PARAMC3==var1[i])[,12])
    }else if(FRANCH[i]==18){
      FFGEN[i]<-as.numeric(filter(KTE_GI,KTE_GI$B_COEFF=="C_FRANCHISE",KTE_GI$B_PARAMC2=="18",KTE_GI$B_PARAMC3==var1[i])[,12])
    }else if(FRANCH[i]==27){
      FFGEN[i]<-as.numeric(filter(KTE_GI,KTE_GI$B_COEFF=="C_FRANCHISE",KTE_GI$B_PARAMC2=="27",KTE_GI$B_PARAMC3==var1[i])[,12])
    }else if(FRANCH[i]==36){
      FFGEN[i]<-as.numeric(filter(KTE_GI,KTE_GI$B_COEFF=="C_FRANCHISE",KTE_GI$B_PARAMC2=="36",KTE_GI$B_PARAMC3==var1[i])[,12])
    }else if(FRANCH[i]==55){
      FFGEN[i]<-as.numeric(filter(KTE_GI,KTE_GI$B_COEFF=="C_FRANCHISE",KTE_GI$B_PARAMC2=="55",KTE_GI$B_PARAMC3==var1[i])[,12])
    }else if(FRANCH[i]==72){
      FFGEN[i]<-as.numeric(filter(KTE_GI,KTE_GI$B_COEFF=="C_FRANCHISE",KTE_GI$B_PARAMC2=="72",KTE_GI$B_PARAMC3==var1[i])[,12])
    }else if(FRANCH[i]==91){
      FFGEN[i]<-as.numeric(filter(KTE_GI,KTE_GI$B_COEFF=="C_FRANCHISE",KTE_GI$B_PARAMC2=="91",KTE_GI$B_PARAMC3==var1[i])[,12])
    }else{
      FFGEN[i]<-1
    }
  }
}
return(FFGEN)}

When I execute it, a message shows up :
4.stop("'arg' must be NULL or a character vector")
3.match.arg(method)
2.filter(KTE_GI, KTE_GI$B_COEFF == "C_FRANCHISE", KTE_GI$B_PARAMC2 == "18", KTE_GI$B_PARAMC3 == "****")

  1. FGEN(CODE_ACT)

Is there anyone who knows what's the problem pls?
(Ps.: I'm french, sorry if there's some mistakes ^^')

Summary

This text will be hidden

Theres a concept in computer science called a 'code smell' Wikipedia.
This sort of mixing of tidyverse and base programming is a strong code smell to me.
if you are filtering on KTE_GI, you don't need to mention it in every filter criteria, B_COEFF is right there to be interpreted in the context of KTE_GI without need of $.

I would encourage you to come up with a different approach to implementing your calculator. it seems to me you need a look up table to interpret FRANCH codes, probably your code could be simplified to a straightforward join followed by filter.

For additional / specific support I would ask for a proper reprex, with representative data to be shared.

[FAQ: How to do a minimal reproducible example ( reprex ) for beginners]

Thank you for your reply! My problem is now solved!

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.