You don't mention WHAT problem you have with this function.
Your screen print shows that RStudio is not happy with the syntax:
see the two red crosses in lines 280 and 281.
Maybe you need a space immediately after if ?
You say you intend to change times but you don't do this.
I think you meant times = ifelse( .... ?