check_rational <- function(rational, x) {
if (!is.null(attr(x, "rational"))) {
stopifnot(
is.logical(rational),
is.logical(attr(x, "rational"))
)
if (rational != attr(x, "rational")) {
warning(
"Conflict detected between attr(x, \"rational\") {",
attr(x, "rational"), "} and user input {rational = ", rational,
"}.\nSetting to ", get_rational(rational, x),
" based on internal testing.", call. = FALSE
)
rational <- get_rational(rational, x)
}
} else if (is.null(rational) & !inherits(x, "POSIXt")) {
if (is.integer(x)) {
rational <- FALSE
} else {
rational <- get_rational(rational, x)
warning("Setting `rational` to ", rational, call. = FALSE)
}
} else if (is.null(rational) & inherits(x, "POSIXt")) {
warning("Setting `rational` to FALSE", call. = FALSE)
rational <- FALSE
} else {
stopifnot(isTRUE(is.logical(rational) & !is.na(rational)))
}
rational
}
get_rational <- function(rational, x) {
if (inherits(x, "POSIXt"))
FALSE
else
!isTRUE(all.equal(as.numeric(x), as.integer(x)))
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.