diff --git a/R/fcast.R b/R/fcast.R index c0dbfd4e3a..7b633823f7 100644 --- a/R/fcast.R +++ b/R/fcast.R @@ -136,6 +136,12 @@ dcast.data.table = function(data, formula, fun.aggregate = NULL, sep = "_", ..., value.var = names(data)[ncol(data)] lvals = value_vars(value.var, names(data)) valnames = unique(unlist(lvals)) + if (any(valnames == "")) { + valnames[valnames == ""] = "" + } + if (any(duplicated(valnames))) { + valnames = make.unique(valnames, sep = sep) + } lvars = check_formula(formula, names(data), valnames, value.var.in.LHSdots, value.var.in.RHSdots) lvars = lapply(lvars, function(x) if (length(x)) x else quote(`.`)) # tired of lapply and the way it handles environments! @@ -252,4 +258,4 @@ dcast.data.table = function(data, formula, fun.aggregate = NULL, sep = "_", ..., setDT(ans); setattr(ans, 'sorted', lhsnames) } else internal_error("empty rhsnames") # nocov return(ans) -} +} \ No newline at end of file