Reads a DataSchema and Data Processing Elements to generate a harmonized dossier from input dataset(s) in a dossier and associated metadata. The function has one argument that can optionally be declared by the user (unique_col_dataset). It refers to the columns which contains name of each harmonized dataset. These two columns are added to ensure that there is always a unique entity identifier when datasets are pooled.

harmo_process(
  dossier,
  dataschema = attributes(dossier)$`Rmonize::DataSchema`,
  data_proc_elem = attributes(dossier)$`Rmonize::Data Processing Elements`,
  harmonized_col_dataset = attributes(dossier)$`Rmonize::harmonized_col_dataset`,
  harmonized_col_id = attributes(dossier)$`Rmonize::harmonized_col_id`
)

Arguments

dossier

List of data frame(s) containing input dataset(s).

dataschema

A DataSchema object.

data_proc_elem

A Data Processing Elements object.

harmonized_col_dataset

A character string identifying the column to use for dataset names. NULL by default.

harmonized_col_id

A character string identifying the name of the column present in every dataset to use as a dataset identifier. NULL by default.

Value

A list of data frame(s), containing harmonized dataset(s). The DataSchema and Data Processing Elements are preserved as attributes of the output harmonized dossier.

Details

A dossier is a named list containing one or more data frames, which are input datasets. The name of each data frame in the dossier will be used as the name of the associated harmonized dataset produced by harmo_process().

A DataSchema is the list of core variables to generate across datasets and related metadata. A DataSchema object is a list of data frames with elements named 'Variables' (required) and 'Categories' (if any). The 'Variables' element must contain at least the name column, and the 'Categories' element must contain at least the variable and name columns to be usable in any function. In 'Variables' the name column must also have unique entries, and in 'Categories' the combination of variable and name columns must also be unique.

The Data Processing Elements specifies the algorithms used to process input variables into harmonized variables in the DataSchema format. It is also contains metadata used to generate documentation of the processing. A Data Processing Elements object is a data frame with specific columns used in data processing: dataschema_variable, input_dataset, input_variables, Mlstr_harmo::rule_category and Mlstr_harmo::algorithm. To initiate processing, the first entry must be the creation of a harmonized primary identifier variable (e.g., participant unique ID).

Examples

{

# Use Rmonize_DEMO to run examples.

library(dplyr)
library(madshapR) # data_dict_filter

dataset_MELBOURNE <- Rmonize_DEMO$dataset_MELBOURNE[1]
dossier <- dossier_create(list(dataset_MELBOURNE))

dataschema <- 
  Rmonize_DEMO$`dataschema - final` %>%
  data_dict_filter('name == "adm_unique_id"')

data_proc_elem <- Rmonize_DEMO$`data_processing_elements - final` %>%
  dplyr::filter(dataschema_variable == 'adm_unique_id',
         input_dataset == 'dataset_MELBOURNE')

# perform harmonization
harmonized_dossier <- harmo_process(dossier,dataschema,data_proc_elem)
glimpse(harmonized_dossier)

}
#> - Data Processing Elements: ------------------------------------------------
#> 
#> --harmonization of : dataset_MELBOURNE --------------------------------
#>     processing 1/1 : adm_unique_id                id created
#> 
#> 
#> - CREATION OF HARMONIZED DATA DICTIONARY : --------------------------------
#> 
#> dataset_MELBOURNE : done
#> 
#> - WARNING MESSAGES (if any): ----------------------------------------------
#> 
#> List of 1
#>  $ dataset_MELBOURNE: tibble [19 × 1] (S3: tbl_df/tbl/data.frame)
#>   ..$ adm_unique_id: chr [1:19] "377943" "497013" "927676" "995667" ...
#>   .. ..- attr(*, "Variables::label:en")= chr "Unique identification code of the participant."
#>   .. ..- attr(*, "Variables::typeof")= chr "character"
#>   .. ..- attr(*, "Variables::index")= chr "1"
#>   .. ..- attr(*, "Variables::Mlstr_harmo::rule_category")= chr "id_creation"
#>   .. ..- attr(*, "Variables::Mlstr_harmo::algorithm")= chr "id_creation"
#>   .. ..- attr(*, "Variables::Rmonize::r_script")= chr "`dataset_MELBOURNE` %>% select('adm_unique_id' = 'id')"
#>   .. ..- attr(*, "Variables::Mlstr_harmo::status")= chr "complete"
#>   .. ..- attr(*, "Variables::Mlstr_harmo::status_detail")= chr "unknown"
#>   ..- attr(*, "madshapR::class")= chr "dataset"
#>  - attr(*, "Rmonize::class")= chr "harmonized_dossier"
#>  - attr(*, "Rmonize::DataSchema")=List of 1
#>   ..$ Variables: tibble [1 × 4] (S3: tbl_df/tbl/data.frame)
#>   ..- attr(*, "madshapR::class")= chr "data_dict_mlstr"
#>   ..- attr(*, "Rmonize::class")= chr "dataschema_mlstr"
#>  - attr(*, "Rmonize::Data Processing Elements")= tibble [1 × 11] (S3: tbl_df/tbl/data.frame)
#>   ..$ index                     : num 1
#>   ..$ dataschema_variable       : chr "adm_unique_id"
#>   ..$ valueType                 : chr NA
#>   ..$ input_dataset             : chr "dataset_MELBOURNE"
#>   ..$ input_variables           : chr "id"
#>   ..$ Mlstr_harmo::rule_category: chr "id_creation"
#>   ..$ Mlstr_harmo::algorithm    : chr "id_creation"
#>   ..$ Mlstr_harmo::status       : chr "complete"
#>   ..$ Mlstr_harmo::status_detail: chr "unknown"
#>   ..$ Mlstr_harmo::comment      : chr NA
#>   ..$ Rmonize::r_script         : chr "`dataset_MELBOURNE` %>% \n  select('adm_unique_id' = 'id')"
#>   ..- attr(*, "Rmonize::class")= chr "data_proc_elem"
#>  - attr(*, "Rmonize::harmonized_col_id")= chr "adm_unique_id"