View source: R/helperFunctions.R
| safe.ifelse | R Documentation |
Type safe if.else implementation that make sure that the output has the same class as the yes condition part. This is important for dates for examples.
safe.ifelse(cond, yes, no)
cond |
the condition |
yes |
what happens if yes condition is met |
no |
what happens if no condition is not met |
type safe value
myDate1 <- NA
myDate2 <- as.Date('2000-01-31', '%Y-%m-%d')
safe.ifelse(is.na(myDate1),myDate2,myDate1)
class(safe.ifelse(is.na(myDate1),myDate2,myDate1))
ifelse(is.na(myDate1),myDate2,myDate1)
class(ifelse(is.na(myDate1),myDate2,myDate1))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.