Skip to content

Commit

Permalink
merge unnamed lists in merge_lists function
Browse files Browse the repository at this point in the history
Unnamed lists can now be overriden by another config section (see rstudio#24)
  • Loading branch information
vpanfilov authored Oct 11, 2019
1 parent c33e4d3 commit 65d407a
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions R/merge.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,32 @@ merge <- function(base_config, merge_config) {
# recursively merge two lists (extracted from code used by rmarkdown
# package to merge _output.yml, _site.yml, front matter, etc.:
# https://github.com/rstudio/rmarkdown/blob/master/R/util.R#L174)
merge_lists <- function (base_list, overlay_list, recursive = TRUE) {
if (length(base_list) == 0)
merge_lists <- function (base_list, overlay_list, recursive = TRUE)
{
if (length(base_list) == 0)
overlay_list
else if (length(overlay_list) == 0)
else if (length(overlay_list) == 0)
base_list
else {
merged_list <- base_list

# merge named lists
for (name in names(overlay_list)) {
base <- base_list[[name]]
overlay <- overlay_list[[name]]
if (is.list(base) && is.list(overlay) && recursive)
if (is.list(base) && is.list(overlay) && recursive)
merged_list[[name]] <- merge_lists(base, overlay)
else {
merged_list[[name]] <- NULL
merged_list <- append(merged_list,
overlay_list[which(names(overlay_list) %in% name)])
merged_list <- append(merged_list, overlay_list[which(names(overlay_list) %in%
name)])
}
}

# merge unnamed lists
if (is.null(names(base_list)) && is.null(names(overlay_list))) {
merged_list <- overlay_list
}
merged_list
}
}
Expand Down

0 comments on commit 65d407a

Please sign in to comment.