You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
dcast only computes default fill if necessary (#5549)
* delete old commented code
* new test for no warning fails
* only compute default fill if missing cells present
* any_NA_int helper
* bugfix #5512
* Update src/fcast.c
Co-authored-by: Xianying Tan <[email protected]>
* Update src/fcast.c
Co-authored-by: Xianying Tan <[email protected]>
* mention warning text
* const int args
* add back ithiscol
* get pointer before for loop
* add test case from Michael
* test min(dbl) and no warning when fill specified
* Revert "delete old commented code"
This reverts commit 2886c4f.
* use suggestions from Michael
* rm inline any_NA_int since that causes install to fail
* clarify comment
* link 5390
* mymin test fails
* compute some_fill using anyNA in R then pass to C
* Update R/fcast.R
Co-authored-by: Michael Chirico <[email protected]>
* Update R/fcast.R
Co-authored-by: Michael Chirico <[email protected]>
* dat_for_default_fill is zero-row dt
* !length instead of length==0
* new dcast tests with fill=character
* dat_for_default_fill is dat again, not 0-row, because that causes some test failure
---------
Co-authored-by: Xianying Tan <[email protected]>
Co-authored-by: Michael Chirico <[email protected]>
Copy file name to clipboardExpand all lines: NEWS.md
+2Lines changed: 2 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -28,6 +28,8 @@
28
28
29
29
3.Optimized`shift`pergroupproducedwrongresultswhensimultaneouslysubsetting, forexample, `DT[i==1L, shift(x), by=group]`, [#5962](https://github.com/Rdatatable/data.table/issues/5962). Thanks to @renkun-ken for the report and Benjamin Schwendinger for the fix.
30
30
31
+
4.`dcast(fill=NULL)`onlycomputesdefaultfillvalueifnecessary, whicheliminatessomeprevious warnings (forexample, whenfun.aggregate=minormax, warningwasNAsintroducedbycoerciontointegerrange) whichwerepotentiallyconfusing, [#5512](https://github.com/Rdatatable/data.table/issues/5512), [#5390](https://github.com/Rdatatable/data.table/issues/5390). Thanks to Toby Dylan Hocking for the fix.
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))
errmsg= gettext("Aggregating function(s) should take vector inputs and return a single value (length=1). However, function(s) returns length!=1. This value will have to be used to fill any missing combinations, and therefore must be length=1. Either override by setting the 'fill' argument explicitly or modify your function to handle this case appropriately.")
if (any(lengths(list.of.columns) !=1L)) stopf("Aggregating function(s) should take vector inputs and return a single value (length=1). However, function(s) returns length!=1. This value will have to be used to fill any missing combinations, and therefore must be length=1. Either override by setting the 'fill' argument explicitly or modify your function to handle this case appropriately.")
if (!length(x)) stop("calling mymin on vector of length 0")
3737
+
min(x)
3738
+
}
3739
+
test(1102.39, dcast(DT, . ~ chr, mymin, value.var="int"), data.table(.=".",a=1L,b=2L,key=".")) # fill not used in output, so default fill not computed.
3740
+
ans <- data.table(int=1:3, a=c(1L,NA,NA), b=c(NA,2L,3L), key="int")
3741
+
test(1102.40, dcast(DT, int ~ chr, min, value.var="int"), ans, warning=c("no non-missing arguments to min; returning Inf", "inf (type 'double') at RHS position 1 out-of-range(NA) or truncated (precision lost) when assigning to type 'integer' (target vector)")) # warning emitted when coercing default fill since as.integer(min(integer()) is Inf) is NA.
3742
+
test(1102.41, dcast(DT, int ~ chr, mymin, value.var="int", fill=NA), ans) # because fill=NA is provided by user, no need to call mymin(integer()).
3743
+
test(1102.42, dcast(DT, int ~ chr, min, value.var="dbl"), data.table(int=1:3, a=c(4,Inf,Inf), b=c(Inf,5,6), key="int"), warning="no non-missing arguments to min; returning Inf") # only one warning, because no coercion.
3744
+
test(1102.43, dcast(DT, int ~ chr, min, value.var="dbl", fill="coerced to NA"), data.table(int=1:3, a=c(4,NA,NA), b=c(NA,5,6), key="int"), warning=c("Coercing 'character' RHS to 'double' to match the type of target vector.", "NAs introduced by coercion"))
3745
+
test(1102.44, dcast(DT, int ~ ., value.var="dbl", fill="ignored"), data.table(int=1:3, .=c(4,5,6), key="int"))
0 commit comments