change_case_from_spec: Convert table name and field case

View source: R/change_case_from_spec.R

change_case_from_specR Documentation

Convert table name and field case

Description

change_case_from_spec() renames from one case to another from the file spec.

native_to_snake_case() is a convenience wrapper around change_case_from_spec() to convert from native case to snake_case. This function will also add any missing columns from the spec to the model.

snake_to_native_case() is a convenience wrapper around change_case_from_spec() to convert from snake_case to the native case.

Usage

change_case_from_spec(
  table_list,
  table_spec,
  from_case = NULL,
  to_case = NULL,
  add_missing = FALSE,
  add_missing_by_type = NULL
)

native_to_snake_case(table_list, table_spec = data_spec(table_list))

snake_to_native_case(table_list, table_spec = data_spec(table_list))

Arguments

table_list

A list of tables to rename.

table_spec

Data model specification object.

from_case

String name of the case the object originates from. If NULL, defaults to the 'native' case.

to_case

String name of the case to convert to. If NULL, defaults to the 'native' case.

add_missing

Logical whether to add in missing tables and columns.

add_missing_by_type

Character vector of values from the spec 'type' column. Only tables of this type will be added back in if add_missing = TRUE.

Details

This function relies on names from a spec file. In order for this to work consistently, a few things are assumed.

The 'native' case tables are specified by the column named 'table' in both the 'tables' and 'fields' data frames of the spec. The fields for the native case are specified by the column named 'field' in the 'fields data frame of the spec.

Any other valid case (e.g., 'new_case') specifies the table name in the 'tables' data frame with the suffix "_table" (e.g., 'new_case_table'). The field names are specified in the 'fields' table with the suffix "_name" (e.g., 'new_case_name').

To access this specific case for conversion, simply use 'new_case' as the argument value for either from_case or to_case.

See Also

Other Data Spec Functions: add_missing_spec_cols(), add_missing_spec_tables(), assert_case(), check_spec(), coerce_to_spec(), data_case()


Technomics/costmisc documentation built on Nov. 12, 2024, 8:05 a.m.