listBuilder: Build a possibly nested list.

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

Description

Build a possibly nested list using the result of a function.

Usage

1
 listBuilder(x,FUN=NULL,fargs=NULL)

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.

fargs

A list of the remaining arguments to FUN.

Details

listBuilder descends the list structure of x if it is a list until it encounters a non-list element. It then passes that element as the first argument to FUN and returns the value of FUN. This may be a list of elements, replacing the original element, hence the name.

Value

If x is not a list and FUN is NULL, x is returned. If FUN creates a list from one or more elements of x, a list or nested list will be returned. Successive calls to listBuilder can rapidly create very large, deeply nested list structures.

Author(s)

Jim Lemon

See Also

list

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
 # define a function that splits a vector into a list
 splitvec<-function(x) {
  xlen<-length(x)
  if(xlen > 1) {
   newx<-vector("list",xlen)
   for(newlist in 1:xlen) newx[[newlist]]<-x[newlist]
   return(newx)
  }
  return(x)
 }
 testlist<-list(c(9,16),list(25,c(36,49)))
 listBuilder(testlist,splitvec)

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

Related to listBuilder in crank...