[6265] in s-news-athena

home help back first fref pref prev next nref lref last post

Re: Using ...

daemon@ATHENA.MIT.EDU (Scott Chasalow)
Thu Jan 26 15:53:04 1995

Date: Thu, 26 Jan 1995 18:52:16 GMT
From: Scott Chasalow <sasssc@scri.sari.ac.uk>
To: s-news@utstat.toronto.edu
Cc: dmurdoch@pickard.mast.QueensU.CA

> Is there an easy way to pass a censored version of ... to axis(), with
> all the non-axis arguments deleted?
> 
> Duncan Murdoch
> 

Hi,

"Easy" is debatable.  But you can do something like:

x _ list(...)

# Now keep only those arguments you want to pass to axis(),  by something like:
x _ x[intersect(names(x),allowed.names)]

Here,  allowed.names is a character vector of the names of all the arguments
you might ever want to be allowed to be passed to axis().  If there are 
arguments to axis() that you want hard-wired in the function,  you must tack
them on to the list "x" before calling do.call().
In some cases it may be more convenient to specify arguments you do NOT want
to be allowed to be passed to axis().  You can remove whatever arguments you 
don't want to pass to axis() by keeping the subset of x NOT in the
intersection between x and the disallowed arguments with something like:

x _ x[is.na(match(names(x),nogood))]  

where nogood is a character vector giving the names of the DISALLOWED arguments.


A function collecting these steps is given below.  A call might look like:

dots.subset(axis,VALUES=list(side=4,at=1:3),
     BAD.NMS=c("xlim","ylim","xlab","ylab"),...)

Default is to pass all arguments in ... (and only those arguments) to function
list().

===========================================================================
As an aside,  to get the complement of an intersection,  I WANTED to use

x _ x[-match(nogood,names(x),nomatch=0)].  

This works fine unless the intersection is empty,  in which case x becomes
numeric(0) instead of being unchanged!  The reason is that x[-0] is numeric(0):

> x
 a b c 
 1 2 3
> x[-2]
 a c 
 1 3
> x[-c(2,0)]
 a c 
 1 3
> x[-0]
numeric(0)

Anyone else find this behaviour of "[" unacceptable?  I want to have 
junk[-0] be the same as junk,  since we are deleting an element indexed 
outside the array.
=========================================================================

Cheers,

Scott

=========================================================================
"dots.subset" <- function(FUN = list, VALUES.REQUIRED = NULL, 
        NMS.REQUIRED = names(VALUES.REQUIRED), GOOD.NMS = nx, BAD.NMS, ...)
{
#   DATE WRITTEN:  ?                      LAST REVISED:  26 January 1995
#   AUTHOR:  Scott D. Chasalow (sasssc@scri.sari.ac.uk)
#
	x <- list(...)
	nx <- names(x)
	if(length(x) && (length(nx) == 0 || any(nx == "")))
		stop("Unnamed argument(s) passed in `...'")
	FUN <- substitute(FUN)
	if(is.name(FUN))
		FUN <- as.character(FUN)
	else if(!is.character(FUN))
		stop(paste("Argument FUN must be a function or character", 
			"string giving the name of a function"))
	arglist <- NULL
	if(length(x)) {
		if(!missing(BAD.NMS)) {
			if(!missing(GOOD.NMS))
				stop(paste("Only one of arguments `GOOD.NMS'", 
				  "and `BAD.NMS' may be specified"))
			else arglist <- x[is.na(match(nx, BAD.NMS))]
		}
		else arglist <- x[intersect(nx, GOOD.NMS)]
	}
	if(length(VALUES.REQUIRED)) {
		if(length(NMS.REQUIRED) == 0)
			stop("Argument `NMS.REQUIRED' has zero length; no names available for VALUES.REQUIRED"
				)
		VALUES.REQUIRED <- as.list(VALUES.REQUIRED)	
	# names(VALUES.REQUIRED) are lost!
		names(VALUES.REQUIRED) <- NMS.REQUIRED
		arglist <- c(VALUES.REQUIRED, arglist)
	}
	do.call(FUN, as.list(arglist))
}

home help back first fref pref prev next nref lref last post