Skip to content

Commit

Permalink
Improved warning message in fcast.R (#5976)
Browse files Browse the repository at this point in the history
* Improved warning message

* added test

* Updating news

* Update fcast.R

* Update tests.Rraw

* final touches

* final touches

* restore spacing

* Update NEWS.md

Co-authored-by: Michael Chirico <michaelchirico4@gmail.com>

* use internal helpers correctly

* Update R/fcast.R

Co-authored-by: Michael Chirico <michaelchirico4@gmail.com>

* Reverting changes to po/pot files

* Update tests.Rraw

* Fixed test

* implemented regex for test

* typo, improve clarity

---------

Co-authored-by: nitish jha <nitishjha@nitishs-MacBook-Air.local>
Co-authored-by: Michael Chirico <michaelchirico4@gmail.com>
  • Loading branch information
3 people authored Mar 6, 2024
1 parent 097ada4 commit d09d741
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@

5. Input files are now kept open during `mmap()` when running under Emscripten, [emscripten-core/emscripten#20459](https://github.com/emscripten-core/emscripten/issues/20459). This avoids an error in `fread()` when running in WebAssembly, [#5969](https://github.com/Rdatatable/data.table/issues/5969). Thanks to @maek-ies for the report and @georgestagg for the PR.

6. `dcast()` message about `fun.aggregate` defaulting to `length()` when aggregation is necessary, which could be confusing if duplicates were unexpected, does better explaining the behavior and suggesting alternatives, [#5217](https://github.com/Rdatatable/data.table/issues/5217). Thanks @MichaelChirico for the suggestion and @Nj221102 for the fix.

# data.table [v1.15.0](https://github.com/Rdatatable/data.table/milestone/29) (30 Jan 2024)

## BREAKING CHANGE
Expand Down
2 changes: 1 addition & 1 deletion R/fcast.R
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ dcast.data.table = function(data, formula, fun.aggregate = NULL, sep = "_", ...,
if (is.null(fun.call)) {
oo = forderv(dat, by=varnames, retGrp=TRUE)
if (attr(oo, 'maxgrpn', exact=TRUE) > 1L) {
messagef("Aggregate function missing, defaulting to 'length'")
messagef("'fun.aggregate' is NULL, but found duplicate row/column combinations, so defaulting to length(). That is, the variables %s used in 'formula' do not uniquely identify rows in the input 'data'. In such cases, 'fun.aggregate' is used to derive a single representative value for each combination in the output data.table, for example by summing or averaging (fun.aggregate=sum or fun.aggregate=mean, respectively). Check the resulting table for values larger than 1 to see which combinations were not unique. See ?dcast.data.table for more details.", brackify(varnames))
fun.call = quote(length)
}
}
Expand Down
4 changes: 2 additions & 2 deletions inst/tests/tests.Rraw
Original file line number Diff line number Diff line change
Expand Up @@ -13593,7 +13593,7 @@ test(1962.087, dcast(DT, a ~ b, value.var = 'b'),
test(1962.088, dcast(DT[0L, ], a ~ c, value.var = 'b'), data.table(a=numeric(), key="a")) #1215
test(1962.089, dcast(DT, a ~ c, value.var = 'b'),
data.table(a = c(1, 2), `2` = c(0L, 2L), `4` = c(2L, 0L), key = 'a'),
message = 'Aggregate function missing')
message = ".*'fun\\.aggregate' is NULL.*defaulting to length\\(\\).*\\[a, c\\].*")

## IDateTime.R
x = as.IDate('2018-08-01')
Expand Down Expand Up @@ -18193,7 +18193,7 @@ test(2241.04, set(DT, j="D", value=2), data.table(A=1:3, b=4:6, C=1, D=2, key="A
test(2241.05, colnames(DT)[2]<-"B", "B")
test(2241.06, DT, data.table(A=1:3, B=4:6, C=1, D=2, key="A"))
test(2241.07, set(DT, j="E", value=3), data.table(A=1:3, B=4:6, C=1, D=2, E=3, key="A"))
test(2241.08, names(DT)<-letters[1:5], letters[1:5]) # R doesn't copy *tmp* when assigning to all names
test(2241.08, names(DT)<-letters[1:5], letters[1:5]) # R doesn't copy *tmp* when assigning to all names
test(2241.09, DT, data.table(a=1:3, b=4:6, c=1, d=2, e=3, key="a"))
test(2241.10, set(DT, j="f", value=4), data.table(a=1:3, b=4:6, c=1, d=2, e=3, f=4, key="a"))

Expand Down

0 comments on commit d09d741

Please sign in to comment.