<commit_before>#' Function to melt data.frame from one or multiple arrays
#'
#' @param ...       Array[s] or data.frame[s] to be melted
#' @param dimnames  List of names along the dimensions
#' @param na_rm     Remove rows with NAs
#' @return   data.frame with 'value' (or object names if multiple) indexed by axes
#' @export
melt = function(..., dimnames=NULL, na_rm=TRUE) {
    dots = lapply(named_dots(...), eval)
    for (i in seq_along(dots)) {
        if (!is.null(dimnames))
            names(dimnames(dots[[i]])) = dimnames[1:length(dim(dots[[i]]))]
        dots[[i]] = melt_one(dots[[i]], na_rm=na_rm)
        if (length(dots) > 1)
            colnames(dots[[i]])[ncol(dots[[i]])] = names(dots)[i]
    }

    Reduce(function(a,b) merge(a,b,all=!na_rm), dots)
}

melt_one = function(x, dn=dimnames(x), na_rm=FALSE) {
    dns = expand.grid(dn, KEEP.OUT.ATTRS=FALSE, stringsAsFactors=FALSE)
    re = cbind(dns, value=c(x))
    if (na_rm)<commit_msg>access objs in correct env<commit_after>#' Function to melt data.frame from one or multiple arrays
#'
#' @param ...       Array[s] or data.frame[s] to be melted
#' @param dimnames  List of names along the dimensions
#' @param na_rm     Remove rows with NAs
#' @return   data.frame with 'value' (or object names if multiple) indexed by axes
#' @export
melt = function(..., dimnames=NULL, na_rm=TRUE) {
    dots = lapply(named_dots(...), eval, envir=parent.frame())
    for (i in seq_along(dots)) {
        if (!is.null(dimnames))
            names(dimnames(dots[[i]])) = dimnames[1:length(dim(dots[[i]]))]
        dots[[i]] = melt_one(dots[[i]], na_rm=na_rm)
        if (length(dots) > 1)
            colnames(dots[[i]])[ncol(dots[[i]])] = names(dots)[i]
    }

    Reduce(function(a,b) merge(a,b,all=!na_rm), dots)
}

melt_one = function(x, dn=dimnames(x), na_rm=FALSE) {
    dns = expand.grid(dn, KEEP.OUT.ATTRS=FALSE, stringsAsFactors=FALSE)
    re = cbind(dns, value=c(x))
    if (na_rm)
{'fraction_non_alphanumeric': 0.17429305912596402, 'fraction_numerical': 0.002056555269922879, 'mean_word_length': 3.557377049180328, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1802105', 'n_tokens_mistral': 743, 'n_tokens_neox': 713, 'n_words': 170}