[R] How to make a function aware of its own call arguments

S Ellison S.Ellison at LGCGroup.com
Thu Mar 24 16:16:53 CET 2016


> Are you aware of any function what would query the original function call
> arguments no matter what happens in the function?

Use missing() first.
If you can't use missing() first, or use it early in a parent function and pass a flag, you could perhaps pass a copy of the parent function call to the daughter function and see if an argument was included in the call. Example:

f1 <- function(x,  ...) {
	if(missing(x)) x<-3
	f2(x, match.call())
}

f2 <- function(x, f1.call) {
	testx <- if(is.null(f1.call$x)) "x was absent in f1" else "x specified in f1"
	xval <- paste("x now set to", x)
	
	cat(sprintf("%s\n%s\n",testx, xval))
	
}

f1()

f1(x=2)





*******************************************************************
This email and any attachments are confidential. Any use...{{dropped:8}}



More information about the R-help mailing list