vector.R 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #' @export
  2. ral_vector <- function(..., .data = NULL, .subclass = NULL, .meta = NULL) {
  3. val <- if (is.null(.data)) {
  4. list(...)
  5. } else {
  6. stopifnot(is.list(`.data`))
  7. `.data`
  8. }
  9. class(val) <- c(.subclass, "ral_vector")
  10. ral_meta_data <- if (!is.null(.meta) && inherits(.meta, "ral_map")) {
  11. .meta
  12. }
  13. new_vctr(val, ral_meta_data = ral_meta_data, class = class(val), inherit_base_type = TRUE)
  14. }
  15. #' @export
  16. set_meta_data.ral_vector <- function(x, val, envir = NULL) {
  17. attr(x, "ral_meta_data") <- val
  18. x
  19. }
  20. #' @export
  21. meta_data.ral_vector <- function(x) {
  22. attr(x, "ral_meta_data", exact = TRUE)
  23. }
  24. #' @export
  25. #' @include format.R
  26. format.ral_vector <- function(x, ...) {
  27. paste0(
  28. "[",
  29. paste0(vapply(x, function(x) llr_format(x), character(1)), collapse = " "),
  30. "]"
  31. )
  32. }
  33. #' @export
  34. #' @include format.R
  35. print.ral_vector <- default_print
  36. #' @export
  37. vec_ptype2.ral_vector.list <- function(x, y, ...) {
  38. ral_vector()
  39. }
  40. #' @export
  41. vec_ptype2.list.ral_vector <- function(x, y, ...) {
  42. ral_vector()
  43. }
  44. #' @export
  45. vec_cast.character.llr_boolean <- function(x, to, ...) {
  46. format(x)
  47. }