0

I implemented a function 'identify_case' i.e.:

##  Function that identify the gaps of NAs according to their length
identify_case = function(df, variable, seuil) {

df$value   = ifelse(is.na(df[,variable])==TRUE,1,0)
df$temp    = rep.int(rle(df$value)$lengths, rle(df$value)$lengths)
df$gap     = ifelse(df$value == 1, df$temp, 0)
df$temp    = NULL
df$case.nb = ifelse((df$gap > 0 & df$gap <= seuil),"cas1",ifelse((df$gap > 
seuil),"cas2","OK"))
return(df)

}

When I call the function using the code below:

temp.df      = identify_case(df = temporary_df,variable = "energy_NA",seuil 
= 3)

I get the error :

Error in identify_case(df = temporary_df, variable = "energy_NA", seuil = 3): 
unused argument (seuil = 3)

What is weird is when I add the line

seuil = seuil 

at the beginning of the function 'identify_case'.I do not get any error and the code is executed perfectly.

i.e.:

## Function that identify the gaps of NAs according to their length
identify_case = function(df, variable, seuil) {

seuil = seuil


df$value   = ifelse(is.na(df[,variable])==TRUE,1,0)
df$temp    = rep.int(rle(df$value)$lengths, rle(df$value)$lengths)
df$gap     = ifelse(df$value == 1, df$temp, 0)
df$temp    = NULL
df$case.nb = ifelse((df$gap > 0 & df$gap <= seuil),"cas1",ifelse((df$gap > 
seuil),"cas2","OK"))
return(df)

}

Does anyone what is going on here?

Amandine.G
  • 181
  • 1
  • 2
  • 9
  • 4
    I would restart R and recheck in a fresh session. Your function runs fine for me with that argument and requires no modification. My best guess is that in editing and reloading your function you are mistakenly calling an older version that does not have the `seuil` argument in it's definition. – joran Feb 19 '19 at 19:06
  • Update : thank you Joran, you are right. I was mistakenly calling an older version of the function that was in another script that I called with the command "source" and this function only had 2 arguments. Thus the argument "seuil" was missing. My bad, my mistake was really stupid! – Amandine.G Feb 20 '19 at 09:43

0 Answers0