R/ptype.R

Defines functions dm_ptype

Documented in dm_ptype

#' Prototype for a dm object
#'
#' @description
#' The prototype contains all tables, all primary and foreign keys,
#' but no data.
#' All tables are truncated and converted to zero-row tibbles,
#' also for remote data models.
#' Columns retain their type.
#' This is useful for performing creation and population of a database
#' in separate steps.
#'
#' @inheritParams dm_has_fk
#' @export
#' @examplesIf dm:::dm_has_financial()
#' dm_financial() %>%
#'   dm_ptype()
#'
#' dm_financial() %>%
#'   dm_ptype() %>%
#'   dm_nrow()
dm_ptype <- function(dm) {
  check_not_zoomed(dm)

  # collect() doesn't support n argument for data frames
  # collect() requires n > 0: https://github.com/tidyverse/dbplyr/issues/415
  dm %>%
    dm_get_def() %>%
    mutate(data = map(data, ~ head(.x, 0))) %>%
    dm_from_def() %>%
    collect()
}

Try the dm package in your browser

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

dm documentation built on Nov. 2, 2023, 6:07 p.m.