Skip to content

Commit ff397c0

Browse files
committed
use single-step data.table fn for relocate
1 parent e00dc12 commit ff397c0

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

NAMESPACE

+1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ importFrom(data.table,copy)
6868
importFrom(data.table,key)
6969
importFrom(data.table,rbindlist)
7070
importFrom(data.table,set)
71+
importFrom(data.table,setcolorder)
7172
importFrom(data.table,setkeyv)
7273
importFrom(dplyr,arrange)
7374
importFrom(dplyr,bind_rows)

R/epi_df.R

+4-5
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ NULL
111111
#' @param ... Additional arguments passed to methods.
112112
#' @return An `epi_df` object.
113113
#'
114+
#' @importFrom data.table setcolorder
115+
#'
114116
#' @export
115117
new_epi_df = function(x = tibble::tibble(), geo_type, time_type, as_of,
116118
additional_metadata = list(), ...) {
@@ -159,11 +161,8 @@ new_epi_df = function(x = tibble::tibble(), geo_type, time_type, as_of,
159161

160162
# Reorder columns (geo_value, time_value, ...)
161163
if(sum(dim(x)) != 0){
162-
cols_to_put_first <- colnames(x) %in% c("geo_value", "time_value")
163-
x <- x[, c(
164-
which(cols_to_put_first),
165-
which(!cols_to_put_first)
166-
)]
164+
# Moves columns in place
165+
setcolorder(x, c("geo_value", "time_value"))
167166
}
168167

169168
# Apply epi_df class, attach metadata, and return

0 commit comments

Comments
 (0)