tidyverse / dtplyr
Showing 1 of 3 files from the diff.

@@ -90,14 +90,16 @@
Loading
90 90
91 91
  if (uses_dot_value) {
92 92
    if (!is.null(names_sep)) {
93 -
      .value <- str_separate(measure_vars, into = names_to, sep = names_sep)$.value
93 +
      names_to_setup <- str_separate(measure_vars, into = names_to, sep = names_sep)
94 94
    } else if (!is.null(names_pattern)) {
95 -
      .value <- str_extract(measure_vars, into = names_to, names_pattern)$.value
95 +
      names_to_setup <- str_extract(measure_vars, into = names_to, names_pattern)
96 96
    } else {
97 97
      abort("If you use '.value' in `names_to` you must also supply
98 98
            `names_sep' or `names_pattern")
99 99
    }
100 100
101 +
    .value <- names_to_setup$.value
102 +
101 103
    v_fct <- factor(.value, levels = unique(.value))
102 104
    measure_vars <- split(measure_vars, v_fct)
103 105
    values_to <- names(measure_vars)
@@ -105,6 +107,23 @@
Loading
105 107
106 108
    if (multiple_names_to) {
107 109
      variable_name <- names_to[!names_to == ".value"]
110 +
111 +
      .value_ids <- split(names_to_setup[[variable_name]], v_fct)
112 +
      .value_id <- .value_ids[[1]]
113 +
114 +
      # Make sure data is "balanced"
115 +
      # https://github.com/Rdatatable/data.table/issues/2575
116 +
      # The list passed to measure.vars also needs the same number of column names per element
117 +
      equal_ids <- vapply(
118 +
        .value_ids[-1],
119 +
        function(.x) isTRUE(all.equal(.value_id, .x)),
120 +
        logical(1)
121 +
      )
122 +
      if (all(equal_ids)) {
123 +
        .value_id <- vctrs::vec_rep_each(.value_id, length(pull(data)))
124 +
      } else {
125 +
        abort("`data.table::melt()` doesn't currently support melting of unbalanced datasets.")
126 +
      }
108 127
    }
109 128
  } else if (multiple_names_to) {
110 129
    if (is.null(names_sep) && is.null(names_pattern)) {
@@ -152,7 +171,9 @@
Loading
152 171
    out <- mutate(out, !!variable_name := gsub(paste0("^", names_prefix), "", !!sym(variable_name)))
153 172
  }
154 173
155 -
  if (multiple_names_to && !uses_dot_value) {
174 +
  if (multiple_names_to && uses_dot_value) {
175 +
    out <- mutate(out, !!variable_name := !!.value_id)
176 +
  } else if (multiple_names_to && !uses_dot_value) {
156 177
    if (!is.null(names_sep)) {
157 178
      into_cols <- str_separate(pull(out, !!sym(variable_name)), names_to, sep = names_sep)
158 179
    } else {
Files Coverage
R 93.51%
Project Totals (29 files) 93.51%
1
comment: false
2

3
coverage:
4
  status:
5
    project:
6
      default:
7
        target: auto
8
        threshold: 1%
9
        informational: true
10
    patch:
11
      default:
12
        target: auto
13
        threshold: 1%
14
        informational: true
Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file. The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files. The size and color of each slice is representing the number of statements and the coverage, respectively.
Grid
Each block represents a single file in the project. The size and color of each block is represented by the number of statements and the coverage, respectively.
Loading