summarize_field gets the total rows, distinct value count, valueset, and null counts for a single field in a table. To get the summary of more than 1 field, see summarize_fields. To summarize an entire table or schema without hand-selecting fields, see summarize_table and summarize_schema respectively.

summarize_field(
  conn,
  conn_fun,
  schema,
  table,
  field,
  verbose = TRUE,
  render_sql = TRUE,
  render_only = FALSE,
  warn_no_rows = TRUE,
  ...
)

See also

Other summary functions: summarize_fields(), summarize_schema(), summarize_table()

Examples

library(pg13) create_test_schema <- function(conn) { if (!schema_exists(conn = conn, schema = "test_schema")) { cli::cli_rule("Create 'test_schema' Schema") create_schema(conn = conn, schema = "test_schema") } } conn <- local_connect(dbname = "pg13_test")
#> Error in rJava::.jcall(jdbcDriver, "Ljava/sql/Connection;", "connect", as.character(url), p): org.postgresql.util.PSQLException: Connection to localhost:5432 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.
create_test_schema(conn = conn)
#> Error in h(simpleError(msg, call)): error in evaluating the argument 'conn' in selecting a method for function 'dbGetQuery': object 'conn' not found
write_table(conn = conn, schema = "test_schema", table_name = "test_table", drop_existing = TRUE, data = data.frame(A = 1:3, B = letters[1:3]))
#> [2021-06-20 15:26:27] Dropping test_schema.test_table...
#> Error in check_conn_status(conn = conn): object 'conn' not found
write_table(conn = conn, schema = "test_schema", table_name = "test_table2", drop_existing = TRUE, data = data.frame(C = rep(NA, 3), D = c(TRUE, FALSE, FALSE)))
#> [2021-06-20 15:26:27] Dropping test_schema.test_table2...
#> Error in check_conn_status(conn = conn): object 'conn' not found
write_table(conn = conn, schema = "test_schema", table_name = "test_table3", drop_existing = TRUE, data = data.frame(E = c(1.25, 343.31341, 5), G = c(Sys.Date(), Sys.Date()-100, Sys.Date()-1000)))
#> [2021-06-20 15:26:27] Dropping test_schema.test_table3...
#> Error in check_conn_status(conn = conn): object 'conn' not found
summarize_fields(conn = conn, schema = "test_schema", table = "test_table", fields = c("A", "B"))
#> Error in h(simpleError(msg, call)): error in evaluating the argument 'conn' in selecting a method for function 'dbListFields': object 'conn' not found
# Case is ignored summarize_fields(conn = conn, schema = "test_schema", table = "test_table", fields = c("a", "b"))
#> Error in h(simpleError(msg, call)): error in evaluating the argument 'conn' in selecting a method for function 'dbListFields': object 'conn' not found
summarize_fields(conn = conn, schema = "test_schema", table = "test_table2", fields = c("c", "D"))
#> Error in h(simpleError(msg, call)): error in evaluating the argument 'conn' in selecting a method for function 'dbListFields': object 'conn' not found
# To summarize an entire table (all the fields without manually inputting them) summarize_table(conn = conn, schema = "test_schema", table = "test_table3")
#> [2021-06-20 15:26:27] SQL: N/A #> [2021-06-20 15:26:27] Listing Fields...
#> Error in h(simpleError(msg, call)): error in evaluating the argument 'conn' in selecting a method for function 'dbListFields': object 'conn' not found
# An entire schema can also be summarized summarize_schema(conn = conn, schema = "test_schema")
#> [2021-06-20 15:26:27] SQL: N/A #> [2021-06-20 15:26:27] Listing Tables...
#> Error in h(simpleError(msg, call)): error in evaluating the argument 'conn' in selecting a method for function 'dbListTables': object 'conn' not found
drop_schema(conn = conn, schema = "test_schema", cascade = TRUE)
#> Error in check_conn_status(conn = conn): object 'conn' not found
dc(conn = conn)
#> [2021-06-20 15:26:27] Postgres connection was already closed