Skip to content

Commit 67db7f7

Browse files
authored
refine froll docs (#7383)
1 parent 59f966c commit 67db7f7

File tree

2 files changed

+26
-46
lines changed

2 files changed

+26
-46
lines changed

man/froll.Rd

Lines changed: 13 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,11 @@
4545
}
4646
\arguments{
4747
\item{x}{ Integer, numeric or logical vector, coerced to numeric, on which sliding window calculates an aggregate function. It supports vectorized input, then it needs to be a \code{data.table}, \code{data.frame} or a \code{list}, in which case a rolling function is applied to each column/vector. }
48-
\item{n}{ Integer, non-negative, rolling window size. This is the \emph{total} number of included values in aggregate function. In case of an adaptive rolling function window size has to be provided as a vector for each indivdual value of \code{x}. It supports vectorized input, then it needs to be a vector, or in case of an adaptive rolling a \code{list} of vectors. }
49-
\item{fill}{ Numeric; value to pad by. Defaults to \code{NA}. }
50-
\item{algo}{ Character, default \code{"fast"}. When set to \code{"exact"}, a slower (but more accurate) algorithm is used. It suffers less from floating point rounding errors by performing an extra pass, and carefully handles all non-finite values. It will use multiple cores where available. See Details for more information. }
48+
\item{n}{ Integer, non-negative, non-NA, rolling window size. This is the \emph{total} number of included values in aggregate function. In case of an adaptive rolling function window size has to be provided as a vector for each indivdual value of \code{x}. It supports vectorized input, then it needs to be a vector, or in case of an adaptive rolling a \code{list} of vectors. }
49+
\item{fill}{ Numeric; value to pad by for an incomplete window iterations. Defaults to \code{NA}. When partial=TRUE this argument is ignored. }
50+
\item{algo}{ Character, default \code{"fast"}. When set to \code{"exact"}, a slower (in some cases more accurate) algorithm is used. It will use multiple cores where available. See Details for more information. }
5151
\item{align}{ Character, specifying the "alignment" of the rolling window, defaulting to \code{"right"}. \code{"right"} covers preceding rows (the window \emph{ends} on the current value); \code{"left"} covers following rows (the window \emph{starts} on the current value); \code{"center"} is halfway in between (the window is \emph{centered} on the current value, biased towards \code{"left"} when \code{n} is even). }
52-
\item{na.rm}{ Logical, default \code{FALSE}. Should missing values be removed when calculating window? }
52+
\item{na.rm}{ Logical, default \code{FALSE}. Should missing values be removed when calculating aggregate function on a window? }
5353
\item{has.nf}{ Logical. If it is known whether \code{x} contains non-finite values (\code{NA}, \code{NaN}, \code{Inf}, \code{-Inf}), then setting this to \code{TRUE} or \code{FALSE} may speed up computation. Defaults to \code{NA}. See \emph{has.nf argument} section below for details. }
5454
\item{adaptive}{ Logical, default \code{FALSE}. Should the rolling function be calculated adaptively? See \emph{Adaptive rolling functions} section below for details. }
5555
\item{partial}{ Logical, default \code{FALSE}. Should the rolling window size(s) provided in \code{n} be computed also for leading incomplete running window. See \emph{\code{partial} argument} section below for details. }
@@ -61,24 +61,9 @@
6161

6262
Argument \code{n} allows multiple values to apply rolling function on multiple window sizes. If \code{adaptive=TRUE}, then \code{n} can be a list to specify multiple window sizes for adaptive rolling computation. See \emph{Adaptive rolling functions} section below for details.
6363

64-
When multiple columns and/or multiple window widths are provided, then computations run in parallel. The exception is for \code{algo="exact"}, which runs in parallel even for single column and single window width. By default, data.table uses only half of available CPUs, see \code{\link{setDTthreads}} for details on how to tune CPU usage.
64+
When multiple columns or multiple windows width are provided, then they are run in parallel. The exception is for \code{algo="exact"} or \code{adaptive=TRUE}, which runs in parallel even for single column and single window width. By default, data.table uses only half of available CPUs, see \code{\link{setDTthreads}} for details on how to tune CPU usage.
6565

66-
Adaptive rolling functions are a special case where each
67-
observation has its own corresponding rolling window width. Due to the logic
68-
of adaptive rolling functions, the following restrictions apply:
69-
\itemize{
70-
\item \code{align} only \code{"right"}.
71-
\item if list of vectors is passed to \code{x}, then all
72-
vectors within it must have equal length.
73-
}
74-
75-
When multiple columns or multiple windows width are provided, then they
76-
are run in parallel. The exception is for \code{algo="exact"}, which runs in
77-
parallel already.
78-
79-
Setting \code{options(datatable.verbose=TRUE)} will display various
80-
information about how rolling function processed. It will not print
81-
information in real-time but only at the end of the processing.
66+
Setting \code{options(datatable.verbose=TRUE)} will display various information about how rolling function processed. It will not print information in real-time but only at the end of the processing.
8267
}
8368
\value{
8469
For a non \emph{vectorized} input (\code{x} is not a list, and \code{n} specify single rolling window) a \code{vector} is returned, for convenience. Thus, rolling functions can be used conveniently within \code{data.table} syntax. For a \emph{vectorized} input a list is returned.
@@ -96,8 +81,8 @@
9681
\item (\emph{mean, sum, prod, var, sd}) detect non-finite, re-run non-finite aware.
9782
\item (\emph{max, min, median}) does not detect non-finites and may silently produce an incorrect answer.
9883
}
99-
In general \code{has.nf=FALSE && any(!is.finite(x))} should be considered as undefined behavior. Therefore \code{has.nf=FALSE} should be used with care.
10084
}
85+
In general \code{has.nf=FALSE && any(!is.finite(x))} should be considered as undefined behavior. Therefore \code{has.nf=FALSE} should be used with care.
10186
}
10287
\section{Implementation}{
10388
Most of the rolling functions have 4 different implementations. First factor that decides which implementation is used is the \code{adaptive} argument (either \code{TRUE} or \code{FALSE}), see section below for details. Then for each of those two algorithms there are usually two implementations depending on the \code{algo} argument.
@@ -117,7 +102,7 @@
117102
}
118103
}
119104
\section{Adaptive rolling functions}{
120-
Adaptive rolling functions are a special case where each observation has its own corresponding rolling window width. Therefore, values passed to \code{n} argument must be series corresponding to observations in \code{x}. If multiple windows are meant to be computed, then a list of integer vectors is expected; each list element must be an integer vector of window size corresponding to observations in \code{x}; see Examples. Due to the logic or implementation of adaptive rolling functions, the following restrictions apply
105+
Adaptive rolling functions are a special case where each observation has its own corresponding rolling window width. Therefore, values passed to \code{n} argument must be series corresponding to observations in \code{x}. If multiple windows are meant to be computed, then a list of integer vectors is expected; each list element must be an integer vector of window size corresponding to observations in \code{x}; see Examples. Due to the logic or implementation of adaptive rolling functions, the following restrictions apply:
121106
\itemize{
122107
\item \code{align} does not support \code{"center"}.
123108
\item if list of vectors is passed to \code{x}, then all vectors within it must have equal length due to the fact that length of adaptive window widths must match the length of vectors in \code{x}.
@@ -131,19 +116,14 @@
131116
\section{\code{zoo} package users notice}{
132117
Users coming from most popular package for rolling functions \code{zoo} might expect following differences in \code{data.table} implementation
133118
\itemize{
134-
\item rolling function will always return result of the same length
135-
as input.
119+
\item rolling function will always return result of the same length as input.
136120
\item \code{fill} defaults to \code{NA}.
137-
\item \code{fill} accepts only constant values. It does not support
138-
for \emph{na.locf} or other functions.
121+
\item \code{fill} accepts only constant values. It does not support for \emph{na.locf} or other functions.
139122
\item \code{align} defaults to \code{"right"}.
140-
\item \code{na.rm} is respected, and other functions are not needed
141-
when input contains \code{NA}.
123+
\item \code{na.rm} is respected, and other functions are not needed when input contains \code{NA}.
142124
\item integers and logical are always coerced to numeric.
143-
\item when \code{adaptive=FALSE} (default), then \code{n} must be a
144-
numeric vector. List is not accepted.
145-
\item when \code{adaptive=TRUE}, then \code{n} must be vector of
146-
length equal to \code{nrow(x)}, or list of such vectors.
125+
\item when \code{adaptive=FALSE} (default), then \code{n} must be a numeric vector. List is not accepted.
126+
\item when \code{adaptive=TRUE}, then \code{n} must be vector of length equal to \code{nrow(x)}, or list of such vectors.
147127
}
148128
}
149129
\examples{

0 commit comments

Comments
 (0)