Since you're not using vectorised inputs, better style would be `if(is.null(val)) NA else val`.  Also, I usually recommend avoiding ifelse because of the unexpected class coercions that it does.