Skip to contents

Stores per-column descriptions in the DuckLake catalog with COMMENT ON COLUMN, one name = "comment" pair per column. For data with haven/labelled variable labels, create_table() can store the labels automatically; this function adds or revises them afterward – for example to label a derived variable.

Usage

set_column_comments(table_name, ...)

Arguments

table_name

The table whose columns to describe.

...

Named comments, e.g. USUBJID = "Unique subject identifier". Use NA (or NULL) as a value to clear that column's comment. To pass a named vector built elsewhere, splice it with do.call(set_column_comments, c(list("tbl"), as.list(my_labels))).

Value

Invisibly returns NULL.

Details

All comments from one call are written in a single transaction, so they land as one snapshot. Inside with_transaction() they join the open transaction instead.

DuckLake accepts column comments on tables only. A view takes a comment of its own through set_table_comment(), but not on its columns.

Examples

lake_dir <- tempfile("colcomment_lake_")
dir.create(lake_dir)
attach_ducklake("colcomment_lake", lake_path = lake_dir)
create_table(mtcars, "cars")

set_column_comments(
  "cars",
  mpg = "Miles per US gallon",
  cyl = "Number of cylinders",
  disp = NA # clear this one
)
#> Commented 3 columns on "cars".

detach_ducklake("colcomment_lake", shutdown = TRUE)
unlink(lake_dir, recursive = TRUE)