This should be very easy but all examples I found had slightly different objectives.
I got the lists:
lst1 = list(
Plot = TRUE,
Constrain = c(1:10),
Box = "plot"
)
lst2 = list(
Plot = FALSE,
Lib = "custom"
)
which store default parameters (lst1) and customized ones (lst2) that should overwrite the defaults. I want as a result:
>lst
$Plot
[1] FALSE
$Constrain
[1] 1 2 3 4 5 6 7 8 9 10
$Box
[1] "plot"
$Lib
[1] "custom"
So:
I am sorry, I can't figure it out. I tried merge(), though:
lst=merge(lst2,lst1)
gives
[1] Plot Lib Constrain Box
<0 Zeilen> (oder row.names mit Länge 0)
-- EDIT -- The suggested solution by fabians is exactly what I needed. Even more: it handles nested lists, e.g.
ParametersDefault = list(
Plot = list(
Surface = TRUE,
PlanView= TRUE
),
Constrain = c(1:10),
Box = "plot"
)
Parameters = list(
Plot = list(
Surface = FALSE,
Env = TRUE
),
Lib = "custom"
)
Parameters = modifyList(ParametersDefault,Parameters)
print(Parameters$Plot$Surface)
# [1] FALSE
Thanks so much!
lst1 = list(
Plot = TRUE,
Constrain = c(1:10),
Box = "plot"
)
lst2 = list(
Plot = FALSE,
Lib = "custom"
)
modifyList(lst1, lst2)
# $Plot
# [1] FALSE
#
# $Constrain
# [1] 1 2 3 4 5 6 7 8 9 10
#
# $Box
# [1] "plot"
#
# $Lib
# [1] "custom"
You can try:
> c(lst2, lst1[setdiff(names(lst1), names(lst2))])
$Plot
[1] FALSE
$Lib
[1] "custom"
$Constrain
[1] 1 2 3 4 5 6 7 8 9 10
$Box
[1] "plot"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With