Skip to content

Commit 0d137de

Browse files
committed
update fifelse documentation
1 parent cbe491f commit 0d137de

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

man/fifelse.Rd

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,16 @@
1515
}
1616
\details{
1717
In contrast to \code{\link[base]{ifelse}} attributes are copied from the first non-\code{NA} argument to the output. This is useful when returning \code{Date}, \code{factor} or other classes.
18+
19+
\code{fifelse}, contrary to \code{\link[base]{ifelse}}, evalutes both \code{yes} and \code{no} arguments for type checking regardless the result of \code{test}. This means that neither \code{yes} nor \code{no} should be recursive function calls, use \code{fcase} instead.
1820
}
1921
\value{
2022
A vector of the same length as \code{test} and attributes as \code{yes}. Data values are taken from the values of \code{yes} and \code{no}, eventually \code{na}.
2123
}
2224
\seealso{
2325
\code{\link{fcoalesce}}
26+
27+
\code{\link{fcase}}
2428
}
2529
\examples{
2630
x = c(1:4, 3:2, 1:4)
@@ -37,5 +41,9 @@ fifelse(c(TRUE,FALSE,TRUE), yes, no)
3741
3842
# Example of using the 'na' argument
3943
fifelse(test = c(-5L:5L < 0L, NA), yes = 1L, no = 0L, na = 2L)
44+
45+
# Example showing both 'yes' and 'no' arguments are evaluated, unlike ifelse
46+
fifelse(1 == 1, print("yes"), print("no"))
47+
ifelse(1 == 1, print("yes"), print("no"))
4048
}
4149
\keyword{ data }

0 commit comments

Comments
 (0)