listCrawler: Descend a list, applying a function to each element.

Description Usage Arguments Details Value Author(s) See Also Examples

Description

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

Usage

1
2
 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. The default value of FUN just takes the value of the elements.

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

1
2
3
4
5
6
 # a simple example using the square root function
 testlist<-list(list(9,16),list(25,list(36,49)))
 # first get the default maximum
 listCrawler(testlist,sqrt)
 # then the minimum
 listCrawler(testlist,sqrt,maxval=FALSE)

Example output

$indx
[1] 2 2 2

$element
[1] 49

$value
[1] 7

$indx
[1] 1 1

$element
[1] 9

$value
[1] 3

crank documentation built on May 1, 2019, 9:39 p.m.

Related to listCrawler in crank...