Replace an argument in mainArgs if it also appears in userArgs. Add any argument from userArgs that appears in formals(fun) of the function fun.

replace_add_user_args(mainArgs, userArgs, fun)