rlist (version 0.4.6.1)

list.update: Update a list by appending or modifying its elements.

Description

The function updates each element of a list by evaluating a group of expressions in the scope of the element. If the name of an expression alreadys exists in an list element, then the field with the name will be updated. Otherwise, the value with the name will be appended to the list element. The functionality is essentially done by modifyList.

Usage

list.update(.data, ..., keep.null = FALSE)

Arguments

.data

list

...

A group of labmda expressions

keep.null

Should NULL values be preserved for modifyList

Examples

Run this code
# NOT RUN {
x <- list(p1 = list(type='A',score=list(c1=10,c2=8)),
       p2 = list(type='B',score=list(c1=9,c2=9)),
       p3 = list(type='B',score=list(c1=9,c2=7)))
list.update(x, high=max(score$c1,score$c2), low=min(score$c1,score$c2))
list.update(x, exams=length(score))
list.update(x, grade=ifelse(type=='A', score$c1, score$c2))
list.update(x, score=list(min=0, max=10))
# }

Run the code above in your browser using DataLab