Display the variable dictionary of a data frame in the RStudio viewer
Source:R/view_dictionary.R
view_dictionary.RdGenerates an interactive variable dictionary based on labelled::look_for().
Accepts data frames, tibbles, and also survey objects.
Usage
view_dictionary(data = NULL, details = c("basic", "none", "full"))
view_detailed_dictionary(data = NULL)
to_DT(
x,
caption = NULL,
column_labels = list(pos = "#", variable = "Variable", col_type = "Type", label =
"Variable label", values = "Values", missing = "Missing values", unique_values =
"Unique values", na_values = "User-defined missings (values)", na_range =
"User-defined missings (range)")
)Arguments
- data
a data frame, a tibble or a survey object (if
NULL, will use the text you currently select in RStudio, useful if the function is called through the corresponding addin)- details
add details about each variable (see
labelled::look_for())- x
a tibble returned by
look_for()- caption
an optional caption for the table
- column_labels
Optional column labels
Details
view_dictionary() calls labelled::look_for() and applies to_DT() to
the result to produce an HTML version of the variable dictionary. If you are
using RStudio, it will be displayed by default in the Viewer pane,
allowing to have the dictionary close to your code.
view_detailed_dictionary() is similar to view_dictionary() with the
option details = "full".
These two functions are also available through dedicated addins in RStudio. To use them, select the name of a data frame, then choose View variable dictionary in the Addins menu.
Note
to_DT() is an utility to convert the result of labelled::look_for() into
a DT::datatable().
Examples
if (FALSE) { # interactive()
iris |> view_dictionary()
}
iris |> labelled::look_for(details = TRUE) |> to_DT()