I'm trying to create a function that takes two arguments. It will repeatedly call the first argument, in my case
f()
until f returns that same value 3x in a row. It will then call the second argument
g()
and if g returns the same value as f returned earlier, then the function must return this value. Otherwise it will go back and call the first argument f() again and repeat the cycle.
This is what I have so far.
call_until = function(f, g) {
while(1) {
n = f %>% chunk(3) %>% filter(f, function(v) length(unique(v)) == 1)
x = n()[1]
if (x == g()) {
return(x)
}
}
}
For example, if f returns 4 three times in a row, then go to g. If g equals what f returned three times in a row (which in this example is 4); so if g == 4, then call_until should return 4.