Learn R Programming

siftr (version 1.1.0)

save_dictionary: Save a dataframe's dictionary to a file

Description

Saves a data dictionary in a form that is usable by my dataframe labelling package, tsv2label.

This function creates a folder called "{df name}_dictionary" that contains a file called index.tsv and other files that contain factor level definitions. The folder itself is the data dictionary, and tsv2label looks inside it to do its labelling.

Under normal circumstances you would simply save the dataframe using saveRDS() or save(), both of which save the dataframe exactly as it is, including all of its labels and types. However, there are times when you need to keep the dataframe in a format that won't save its metadata. For example:

  1. You want to export the dataframe to a CSV to share it with others.

  2. You need to keep the data in a particular format to take advantage of another R package, and that package does not save metadata. For example, maybe you're working with very large data and you want to keep it in CSV to take advantage of vroom, or in FST to take advantage of fst.

  3. You are accessing the data remotely (e.g. building it from API calls) and you need to relabel it every time.

Usage

save_dictionary(df, path = stop("'path' must be specified."), ...)

Value

Returns nothing, but prints a message announcing where the dictionary was saved. In an interactive session, it also opens that location in your file explorer.

Arguments

df

(Dataframe) The dataframe whose dictionary you want to save.

path

(Character) The path to save the dictionary to. The dictionary's files will be put into a new subfolder called "{df}_dictionary".

...

(Dots) Other named arguments that will be passed to utils::write.table().

Examples

Run this code
# \donttest{
save_dictionary(CO2, path = tempdir())
# }

Run the code above in your browser using DataLab