push_back: Appends an object to the back of a list

Description Usage Arguments Value Author(s) See Also Examples

Description

Appends an object to the back of a list

Usage

1
push_back(x, y)

Arguments

x

list list of objects

y

list list of objects to append to x

Value

character

Author(s)

Thomas P. Harte

See Also

list

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# zero-length list x: append zero-length object y:
push_back(list(), list())

# zero-length list x: append non-list object:
x<- list()
x<- push_back(x, "one")
x

# unnamed list x: append non-list object:
x<- list()
x[[1]]<- "one"
x<- push_back(x, 2)
x

# named list x: append non-list object:
x<- list()
x[["one"]]<- 1
x<- push_back(x, "two")
x

# unnamed list x: append unnamed list object y:
x<- list()
x[[1]]<- "one"
y<- list(); y[[1]]<- 2;
x<- push_back(x, y)
x

# unnamed list x: append named list object y:
x<- list()
x[[1]]<- "one"
y<- list(); y[[1]]<- 2; names(y)<- "two"
x<- push_back(x, y)
x

# unnamed list x: append named list object y:
x<- list()
x[[1]]<- 1; names(x)<- "one"
y<- list(); y[[1]]<- 2; names(y)<- "two"
x<- push_back(x, y)
x

# note that a particularly useful idiom is to use
# push_back to extract the named elements of a list:
push_back(list(), x)
# thus, if you wish to concatenate the *elements* of
# a list with another list without simply pushing
# back the entire list 'x':
push_back(y, x)
# then use this idiom thusly:
push_back(y, push_back(list(), x))

tharte/tutils documentation built on Feb. 11, 2020, 9:17 a.m.