apexcharter/R/utils.R

62 lines
1.3 KiB
R
Raw Normal View History

2018-07-31 22:56:51 +02:00
# dropNulls
dropNulls <- function(x) {
x[!vapply(x, is.null, FUN.VALUE = logical(1))]
}
`%||%` <- function(x, y) {
if (!is.null(x)) x else y
}
2019-02-14 15:50:58 +01:00
formatNoSci <- function(x) {
if (is.null(x)) return(NULL)
format(x, scientific = FALSE, digits = 15)
}
2018-07-31 22:56:51 +02:00
#' Utility function to create ApexChart parameters JSON
#'
2019-02-14 09:22:57 +01:00
#' @param ax A \code{apexcharts} \code{htmlwidget} object.
2018-07-31 22:56:51 +02:00
#' @param name Slot's name to edit
#' @param ... Arguments for the slot
#'
2019-02-14 09:22:57 +01:00
#' @return A \code{apexcharts} \code{htmlwidget} object.
2018-07-31 22:56:51 +02:00
#'
#' @importFrom utils modifyList
#'
#' @noRd
.ax_opt <- function(ax, name, ...) {
if (is.null(ax$x$ax_opts[[name]])) {
ax$x$ax_opts[[name]] <- list(...)
} else {
ax$x$ax_opts[[name]] <- utils::modifyList(x = ax$x$ax_opts[[name]], val = list(...), keep.null = TRUE)
}
return(ax)
}
#' Utility function to create ApexChart parameters JSON
#'
2019-02-14 09:22:57 +01:00
#' @param ax A \code{apexcharts} \code{htmlwidget} object.
2018-07-31 22:56:51 +02:00
#' @param name Slot's name to edit
#' @param l List of arguments for the slot
#'
2019-02-14 09:22:57 +01:00
#' @return A \code{apexcharts} \code{htmlwidget} object.
2018-07-31 22:56:51 +02:00
#'
#' @noRd
.ax_opt2 <- function(ax, name, l) {
if (is.null(ax$x$ax_opts[[name]])) {
ax$x$ax_opts[[name]] <- l
} else {
ax$x$ax_opts[[name]] <- utils::modifyList(x = ax$x$ax_opts[[name]], val = l, keep.null = TRUE)
}
return(ax)
}