mt_update_factors: Update metadata table

Description Usage Arguments Value Examples

Description

Update the metadata table of a dataset. The function will identify variable columns in df for which rows are missing in meta_tbl and append new rows for each. It will also remove any deprecated rows which do not match columns in the dataset.

Usage

1
2
mt_update_factors(df, meta_tbl, factor_cols = NULL, sep = ";",
  overwrite = F)

Arguments

df

a dataframe or tibble to which the metadata table relates to

meta_tbl

a metadata table associated with df

factor_cols

character string or vector of names of columns containing factors (will only apply to new columns)

sep

separator used to separate codes and definitions for each level in the metadata table (must be the same used throughout meta_tbl)

overwrite

logical. Whether to overwrite already existing metadata entries

Value

an updated meta_tbl with rows added for new df columns and any deprecated rows trimmed.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
## Not run: 
library(gapminder)
df <- gapminder::gapminder
meta_tbl <- readr::read_csv(system.file("extdata", "gapminder_meta.csv", package = "metadatar"))
# update metadata for factor columns from levels
mt_update_factors(df, meta_tbl, overwrite = F)
# update metadata for columns indicated as factors in the metadata table
mt_update_factors(df, meta_tbl, factor_cols = get_factors_meta(meta_tbl), overwrite = F)

## End(Not run)

annakrystalli/metadatar documentation built on May 14, 2019, 6:09 a.m.