Skip to content

Instantly share code, notes, and snippets.

View bjcairns's full-sized avatar

Benjamin Cairns bjcairns

View GitHub Profile
@bjcairns
bjcairns / argument-handling.R
Last active January 17, 2020 13:57
Handling argument priorities (specified vs argument list vs default) in R
# Sometimes during repeat calls to a function, it may be helpful if arguments used in a
# previous call are passed as a list to the function in subsequent calls, to be
# superseded if individual arguments of the same name are given.
#
# The following function prioritises specified arguments (including ... arguments) over an
# argument list, and the argument list over default values.
handle_args <- function(arg1 = 1, arg2 = 2, arglist = list(), ...) {
# Copy default arguments