tidyverse / dtplyr

Compare c692b92 ... +0 ... 0c3f7ef

No flags found

Use flags to group coverage reports by test type, project and/or folders.
Then setup custom commit statuses and notifications for each flag.

e.g., #unittest #integration

#production #enterprise

#frontend #backend

Learn more about Codecov Flags here.


@@ -74,25 +74,7 @@
Loading
74 74
  sim_data <- simulate_vars(.data)
75 75
  locs <- tidyselect::eval_rename(expr(c(...)), sim_data)
76 76
77 -
  new_vars <- .data$vars
78 -
  new_vars[locs] <- names(locs)
79 -
80 -
  vars <- set_names(.data$vars[locs], names(locs))
81 -
  vars <- vars[vars != names(vars)]
82 -
83 -
  if (length(vars) == 0) {
84 -
    return(.data)
85 -
  }
86 -
87 -
  out <- step_call(.data,
88 -
    "setnames",
89 -
    args = list(unname(vars), names(vars)),
90 -
    vars = new_vars,
91 -
    in_place = TRUE
92 -
  )
93 -
94 -
  groups <- rename_groups(.data$groups, vars)
95 -
  step_group(out, groups)
77 +
  step_setnames(.data, .data$vars[locs], names(locs), in_place = TRUE, rename_groups = TRUE)
96 78
}
97 79
98 80

@@ -128,26 +128,13 @@
Loading
128 128
  }
129 129
130 130
  if (!is.null(names_glue)) {
131 -
    out <- step_call(
132 -
      out,
133 -
      "setnames",
134 -
      args = list(old = new_vars, new = glue_vars),
135 -
      vars = c(id_cols, glue_vars),
136 -
      in_place = FALSE
137 -
    )
131 +
    out <- step_setnames(out, new_vars, glue_vars, in_place = FALSE)
138 132
139 133
    # In case of names_sort = TRUE
140 134
    new_vars <- glue_vars
141 135
  } else if (nchar(names_prefix) > 0) {
142 136
    new_names <- paste0(names_prefix, new_vars)
143 -
144 -
    out <- step_call(
145 -
      out,
146 -
      "setnames",
147 -
      args = list(old = new_vars, new = new_names),
148 -
      vars = c(id_cols, new_names),
149 -
      in_place = FALSE
150 -
    )
137 +
    out <- step_setnames(out, new_vars, new_names, in_place = FALSE)
151 138
152 139
    # In case of names_sort = TRUE
153 140
    new_vars <- new_names
@@ -201,13 +188,7 @@
Loading
201 188
  repaired_names <- vctrs::vec_as_names(data_names, repair = repair)
202 189
203 190
  if (any(data_names != repaired_names)) {
204 -
    data <- step_call(
205 -
      data,
206 -
      "setnames",
207 -
      args = list(new = repaired_names),
208 -
      vars = repaired_names,
209 -
      in_place = in_place
210 -
    )
191 +
    data <- step_setnames(data, seq_along(data_names), repaired_names, in_place = in_place)
211 192
  }
212 193
213 194
  data

@@ -2,16 +2,10 @@
Loading
2 2
  stopifnot(is_step(parent))
3 3
  stopifnot(is.character(col_order))
4 4
5 -
  new_step(
6 -
    parent,
5 +
  step_call(parent,
6 +
    "setcolorder",
7 +
    args = list(col_order),
7 8
    vars = col_order,
8 -
    col_order = col_order,
9 -
    needs_copy = !parent$implicit_copy,
10 -
    class = "dtplyr_step_colorder"
9 +
    in_place = !parent$implicit_copy
11 10
  )
12 11
}
13 -
14 -
#' @export
15 -
dt_call.dtplyr_step_colorder <- function(x, needs_copy = x$needs_copy) {
16 -
  call2("setcolorder", dt_call(x$parent, needs_copy), x$col_order)
17 -
}

@@ -0,0 +1,38 @@
Loading
1 +
step_setnames <- function(x, old, new, in_place, rename_groups = FALSE) {
2 +
  stopifnot(is_step(x))
3 +
  stopifnot(is.character(old) || is.integer(old))
4 +
  stopifnot(is.character(new))
5 +
  stopifnot(length(old) == length(new))
6 +
  stopifnot(is_bool(in_place))
7 +
  stopifnot(is_bool(rename_groups))
8 +
9 +
  if (is.integer(old)) {
10 +
    locs <- old
11 +
  } else {
12 +
    locs <- vctrs::vec_match(old, x$vars)
13 +
  }
14 +
15 +
  name_changed <- x$vars[locs] != new
16 +
  old <- old[name_changed]
17 +
  new <- new[name_changed]
18 +
19 +
  if (length(old) == 0) {
20 +
    return(x)
21 +
  }
22 +
23 +
  new_vars <- x$vars
24 +
  new_vars[locs] <- new
25 +
  out <- step_call(x,
26 +
    "setnames",
27 +
    args = list(old, new),
28 +
    vars = new_vars,
29 +
    in_place = in_place
30 +
  )
31 +
32 +
  if (rename_groups) {
33 +
    groups <- rename_groups(x$groups, set_names(old, new))
34 +
    out <- step_group(out, groups)
35 +
  }
36 +
37 +
  out
38 +
}

Learn more Showing 1 files with coverage changes found.

New file R/step-setnames.R
New
Loading file...
Files Coverage
R -0.02% 92.75%
Project Totals (30 files) 92.75%
Loading