Skip to content
Back to formatted view

Raw Message

Message-ID: <1A8C1289955EF649A09086A153E2672403D128F50A@GBTEDVPEXCMB04.corp.lgc-group.com>
Date: 2016-03-24T15:16:53Z
From: S Ellison
Subject: How to make a function aware of its own call arguments
In-Reply-To: <56F3F9A9.1070705@cognigencorp.com>

> 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}}