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
if ((length(ans.ut) ==2L) && all(ans.ut%in% c("double","integer","logical"))) { ## align numeric and integer when function is not type stable: median #7313
10
+
if ("double"%in%ans.ut) {
11
+
if ("integer"%in%ans.ut)
12
+
x[ansmask&all.t=="integer"] = lapply(x[ansmask&all.t=="integer"], as.numeric) ## coerce integer to double
13
+
if ("logical"%in%ans.ut)
14
+
x[ansmask&all.t=="logical"] = lapply(x[ansmask&all.t=="logical"], as.numeric) ## coerce logical to double
15
+
ans.ut="double"
16
+
} elseif ("integer"%in%ans.ut) {
17
+
if ("logical"%in%ans.ut)
18
+
x[ansmask&all.t=="logical"] = lapply(x[ansmask&all.t=="logical"], as.integer) ## coerce logical to integer
19
+
else
20
+
internal_error("simplifylist aligning return types, at that place there should have been some logical types in the answer") # nocov
21
+
ans.ut="integer"
22
+
}
23
+
}
24
+
## file postprocessing to match types
25
+
if (length(ans.ut) ==1L&& equal.lengths(x[ansmask])) {
26
+
if (identical(fill, NA)) { ## different typeof of ans and default fill=NA and lengths of ans equal
27
+
filli= which(!ansmask)
28
+
ans1=x[[which.first(ansmask)]] ## first ans from full window
29
+
x[filli] = rep_len(list(ans1[NA]), length(filli)) ## this will make NA of matching type to ans1 and recycle for all filli
test(6010.2016, frollapply(1:2, 1:2, mean, adaptive=TRUE, align="center"), error="using adaptive TRUE and align 'center' is not implemented")
1617
1620
test(6010.2017, frollapply(list(1:2, 1:3), list(1:2), mean, adaptive=TRUE), error="adaptive rolling function can only process 'X' having equal length of elements; If you want to call rolling function on list having variable length of elements call it for each field separately")
test(6010.2019, frollapply(1:10, list(1:5), mean, adaptive=TRUE), error="length of integer vector(s) provided as list to 'N' argument must be equal to number of observations provided in 'X'")
1620
1623
test(6010.202, frollapply(1:10, 1:5, mean, adaptive=TRUE), error="length of integer vector(s) provided as list to 'N' argument must be equal to number of observations provided in 'X'")
test(6010.704, frollapply(1:5, 2, range), list(NA,1:2,2:3,3:4,4:5)) ## fill=NA could possibly be recycled to length of FUN results
1771
+
test(6010.704, frollapply(1:5, 2, range), data.table(c(NA,1:4),c(NA,2:5))) ## fill=NA could possibly be recycled to length of FUN results, it is now #7313
test(6010.712, as.null(frollapply(1:3, 1, function(x) if (x==1L) sum else if (x==2L) mean else `[`, simplify=TRUE)), NULL) ## as.null as we are only interested in codecov here
1775
1780
test(6010.713, as.null(frollapply(1:3, 1, function(x) `[`, simplify = TRUE)), NULL) ## as.null as we are only interested in codecov here
1781
+
# frollapply simplifylist could be more smart about median results #7313
0 commit comments