For the example at the link which has 3 parts, I would do something like this:
#https://www.sangakoo.com/en/unit/functions-defined-by-parts#:~:text=A%20function%20defined%20by%20parts,value%20of%20the%20independent%20variable.%5D
f <- function(x){
dplyr::case_when(
x <= -3 ~ -x-1,
x>-1 & x<1 ~3,
x >=1 ~ x-2,
TRUE ~ NA_real_ # all other cases
)
}
f(-4)
#> [1] 3
f(-2)
#> [1] NA
f(.5)
#> [1] 3
f(1)
#> [1] -1
Created on 2020-10-04 by the reprex package (v0.3.0)