R/setdiff_list.R

#' Check two lists are equal, up to order of elements
#'
#' @param l1 first list
#' @param l2 second list
#' @author Andrew Pfeiffer <andrew.j.pfeiffer@@gmail.com>
#' @export
#' @note 22 June 2017

setdiff_list <- function(l1, l2){
    # Check that they're lists
    if (!(identical(class(l1), "list") & identical(class(l2), "list")))
        stop("Arguments must be lists")
    # Get names in actual list that are different to those in expected list
    names_diff <- sapply(names(l1), function(x) !identical(l1[[x]], l2[[x]]))
    # Output list
    l1[names_diff]
}
andrewjpfeiffer/rutilities documentation built on May 11, 2019, 6:26 p.m.