ks.test.compare <-
  function(x, ..., stat = NULL){
    stopifnot(!is.null(names(x[["empirical_stats"]])))
    if(is.null(stat)) stat <- names(x[["empirical_stats"]])[[1]]
    strict_match(stat, choices = names(x[["empirical_stats"]]))
    stopifnot(!is.null(x[["empirical_stats"]][[stat]]), !is.null(x[["theoretical_stats"]][[stat]]))
    output <- ks.test(x[["empirical_stats"]][[stat]], x[["theoretical_stats"]][[stat]], ...)
    stat_text <- deparse1(substitute(stat))
    stat_text <- gsub("\"", replacement = "", x = stat_text)
    stat_text <- gsub("\'", replacement = "", x = stat_text)
    output[["data.name"]] <- paste0(deparse1(substitute(x)), "$empirical_stats$",
                                    stat_text, " and ",
                                    deparse1(substitute(x)), "$theoretical_stats$",
                                    stat_text)
    return(output)
  }
