listCrawler {crank}R Documentation

Descend a list, applying a function to each element.

Description

Descend a possibly nested list, seeking the element that has the extreme value of a function.

Usage

 listCrawler(x,FUN=NULL,maxval=TRUE,
  retval=list(indx=vector("numeric",0),element=NULL,value=NA))

Arguments

x The object that will be the first argument of FUN, or a possibly nested list of such objects.
FUN A function that can accept x as its first argument.
maxval Whether to look for maximal (TRUE) or minimal (FALSE) values of the function FUN.
retval The list that is eventually returned.

Details

listCrawler descends the list structure of x applying FUN to any non-list elements it encounters. If the value of FUN is larger or smaller than the current extremum (depending upon the value of maxval), the new value becomes the current extremum.

Value

A list containing:

indx the indices of the element producing the extreme value of FUN.
element The element that produced the extremum.
value The extreme value of FUN.

Author(s)

Jim Lemon

See Also

list, listBuilder

Examples

 # a simple example using the square root function
 testlist<-list(list(9,16),list(25,list(36,49)))
 listCrawler(testlist,sqrt)

[Package crank version 1.0 Index]