Skip to content

Commit b414ddc

Browse files
committed
changes made
1 parent 0586ffd commit b414ddc

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

R/fcast.R

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,12 @@ dcast.data.table = function(data, formula, fun.aggregate = NULL, sep = "_", ...,
136136
value.var = names(data)[ncol(data)]
137137
lvals = value_vars(value.var, names(data))
138138
valnames = unique(unlist(lvals))
139-
valnames[valnames == ""] = "empty_string"
139+
# Preserve empty string column names
140+
if (any(valnames == "")) {
141+
valnames[valnames == ""] = ""
142+
}
140143
if (any(duplicated(valnames))) {
141-
valnames = make.unique(valnames, sep = "_")
144+
valnames = make.unique(valnames, sep = sep)
142145
}
143146
lvars = check_formula(formula, names(data), valnames, value.var.in.LHSdots, value.var.in.RHSdots)
144147
lvars = lapply(lvars, function(x) if (length(x)) x else quote(`.`))
@@ -256,4 +259,4 @@ dcast.data.table = function(data, formula, fun.aggregate = NULL, sep = "_", ...,
256259
setDT(ans); setattr(ans, 'sorted', lhsnames)
257260
} else internal_error("empty rhsnames") # nocov
258261
return(ans)
259-
}
262+
}

0 commit comments

Comments
 (0)