Q:

Concatenate lists with override in R

How do I concatenate two lists in R in such a way that duplicate elements from the second one will override corresponding elements from the first one?
I tried c(), but it keeps duplicates:
l1 <- list(a = 1, b = 2)
l1 <- c(l1, list(b = 3, c = 4))

# $a
# [1] 1
# 
# $b
# [1] 2
# 
# $b
# [1] 3
#
# $c
# [1] 4

I want something that will produce this instead:
# $a
# [1] 1
# 
# $b
# [1] 3
#
# $c
# [1] 4

Hope that there exists something simpler than calling some *apply function?

A:

This works with duplicated:
> l1[!duplicated(names(l1), fromLast=TRUE)]
$a
[1] 1

$b
[1] 3

$c
[1] 4

A:

I suspect that you could get the behavior you want by using the "rlist" package; specifically, list.merge seems to do what you are looking for:
l1 <- list(a = 1, b = 2)
l2 <- list(b = 3, c = 4)
library(rlist)
list.merge(l1, l2)
# $a
# [1] 1
# 
# $b
# [1] 3
# 
# $c
# [1] 4 

Try list.merge(l2, l1) to get a sense of the function's behavior. 

If you have just two lists, as noted by @PeterDee, the list.merge function pretty much makes modifyList accept more than two lists. Thus, for this particular example, you could skip loading any packages and directly do:
modifyList(l1, l2)

