Skip to content

Commit

Permalink
Fix merging of lists (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
TuomasBorman authored Mar 7, 2024
1 parent f291a54 commit 7364147
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -390,12 +390,23 @@
# data.frame
#' @importFrom dplyr full_join
.full_join_list <- function(res){
df <- Reduce(function(df1, df2){
# Get common columns
common_cols <- intersect(colnames(df1), colnames(df2))
# Merge based on common columns
temp <- full_join(df1, df2, by = common_cols)
return(temp)
}, res)
# Remove empty elements
res <- res[ lengths(res) > 0 ]
# If there is more than one element, merge them
if( length(res) > 1 ){
df <- Reduce(function(df1, df2){
# Get common columns
common_cols <- intersect(colnames(df1), colnames(df2))
# Merge based on common columns
temp <- full_join(df1, df2, by = common_cols)
return(temp)
}, res)
} else if( length(res) == 1 ){
# Otherwise if there is only one element, give the element
df <- res[[1]]
} else{
# If all the data.frames were without information, give NULL
df <- NULL
}
return(df)
}

0 comments on commit 7364147

Please sign in to comment.