fhir_melt_all: Melt all columns with multiple entries

View source: R/multiple_entries.R

fhir_melt_allR Documentation

Melt all columns with multiple entries

Description

This function divides all multiple entries in an indexed data frame as produced by fhir_crack() into separate rows.

Usage

fhir_melt_all(indexed_data_frame, brackets, sep, column_name_separator = ".")

Arguments

indexed_data_frame

A data.frame/data.table with indexed multiple entries.

brackets

A character vector of length two, defining the brackets used for the indices.

sep

A character vector of length one defining the separator that was used when pasting together multiple entries in fhir_crack().

column_name_separator

A character string that separates element levels column names. Defaults to ".", which is used when column names were generated automatically with fhir_crack().

Details

The function repeatedly calls fhir_melt() on groups of columns that belong to the same FHIR element (e.g. address.city, address.country and address.type) until every cell contains a single value. If there is more than one FHIR element with multiple values (e.g. multiple address elements and multiple name elements), every possible combination of the two elements will appear in the resulting table. Caution! This creates something like a cross product of all values and can multiply the number of rows from the original table considerably.

Value

A completely molten data.table.

Examples

#unserialize example
bundles <- fhir_unserialize(bundles = example_bundles1)

#crack fhir resources
table_desc <- fhir_table_description(
    resource = "Patient",
    brackets = c("[", "]"),
    sep = " "
)

df <- fhir_crack(bundles = bundles, design = table_desc)

#original data frame
df

#melt all multiple entries
fhir_melt_all(
     indexed_data_frame = df,
     brackets           = c("[", "]"),
     sep = " "
 )

POLAR-fhiR/fhircrackr documentation built on Dec. 24, 2024, 3:06 a.m.