Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

41 line
1.3KB

  1. apply_tag <- function(ll, tag, class = NULL, extra_attributes = NULL) {
  2. lapply(ll, function(x) htmltools::tag(tag, c(x, class = class, extra_attributes)))
  3. }
  4. dots2list <- function(...) {
  5. # Convert dots to list, but return first element if the first element is a list
  6. # and the length of ... is 1
  7. x <- list(...)
  8. if (length(x) == 1 && is.list(x[[1]])) return(x[[1]])
  9. x
  10. }
  11. tag_function <- function(.tag = "div") {
  12. function(...) htmltools::tag(.tag, list(...))
  13. }
  14. validate_value <- function(value = NULL, choices, several.ok = TRUE, value_name = "") {
  15. if (!is.null(value)) {
  16. value_name <- if (nchar(value_name) > 0) glue("`{value_name}` - ") else ""
  17. if (!several.ok && length(value) > 1) {
  18. msg <- glue("{value_name}Using the first of {length(value)} values: {value[1]}")
  19. rlang::warn(msg)
  20. value <- value[1]
  21. }
  22. not_in_choices <- setdiff(value, choices)
  23. if (length(not_in_choices)) {
  24. msg <- glue("{value_name}Ignoring invalid choices: ",
  25. "\"{paste(not_in_choices, collapse = '\", \"')}\"")
  26. rlang::warn(msg)
  27. value <- intersect(value, choices)
  28. }
  29. if (length(value)) {
  30. value
  31. } else {
  32. rlang::abort(glue("{value_name}Must be one of the following valid choices: ",
  33. "\"{paste(choices, collapse = '\", \"')}\""))
  34. }
  35. }
  36. }