R/format-tspec.R

Defines functions format.tspec_object format.tspec_recursive format.tspec_row format.tspec_df print.tspec

Documented in format.tspec_df format.tspec_object format.tspec_recursive format.tspec_row print.tspec

#' @rdname formatting
#' @export
print.tspec <- function(x, width = NULL, ..., names = NULL) {
  names <- .check_print_names_arg(names)
  cat(format(x, width = width, ..., names = names))
  invisible(x)
}

#' @rdname formatting
#' @export
format.tspec_df <- function(x, width = NULL, ..., names = NULL) {
  names <- .check_print_names_arg(names)
  .format_fields(
    "tspec_df",
    fields = x$fields,
    width = width,
    args = list(
      .names_to = if (!is.null(x$names_col)) deparse(x$names_col),
      .vector_allows_empty_list = if (x$vector_allows_empty_list) {
        x$vector_allows_empty_list
      },
      .input_form = if (x$input_form != "rowmajor") .double_quote(x$input_form)
    ),
    force_names = names
  )
}

#' @rdname formatting
#' @export
format.tspec_row <- function(x, width = NULL, ..., names = NULL) {
  names <- .check_print_names_arg(names)
  .format_fields(
    "tspec_row",
    fields = x$fields,
    width = width,
    args = list(
      .vector_allows_empty_list = if (x$vector_allows_empty_list) {
        x$vector_allows_empty_list
      },
      .input_form = if (x$input_form != "rowmajor") .double_quote(x$input_form)
    ),
    force_names = names
  )
}

#' @rdname formatting
#' @export
format.tspec_recursive <- function(x, width = NULL, ..., names = NULL) {
  names <- .check_print_names_arg(names)
  .format_fields(
    "tspec_recursive",
    fields = x$fields,
    width = width,
    args = list(
      .children = .double_quote(x$child),
      .children_to = if (x$child != x$children_to) .double_quote(x$children_to),
      .vector_allows_empty_list = if (x$vector_allows_empty_list) {
        x$vector_allows_empty_list
      },
      .input_form = if (x$input_form != "rowmajor") .double_quote(x$input_form)
    ),
    force_names = names
  )
}

#' @rdname formatting
#' @export
format.tspec_object <- function(x, width = NULL, ..., names = NULL) {
  names <- .check_print_names_arg(names)
  .format_fields(
    "tspec_object",
    fields = x$fields,
    width = width,
    args = list(
      .vector_allows_empty_list = if (x$vector_allows_empty_list) {
        x$vector_allows_empty_list
      },
      .input_form = if (x$input_form != "rowmajor") .double_quote(x$input_form)
    ),
    force_names = names
  )
}

Try the tibblify package in your browser

Any scripts or data that you put into this service are public.

tibblify documentation built on May 9, 2026, 5:07 p.m.