Analyses the content of a variable and its data dictionary (if any), identifies its data type and values accordingly and generates figures and summaries (datatable format). The figures and tables are representations of data distribution, statistics and valid/non valid/empty values (based on the data dictionary information if provided and the data type of the variable). This function can be used to personalize report parameters and is internally used in the function dataset_visualize(). Up to seven objects are generated which include : One datatable of the key elements of the data dictionary, one datatable summarizing statistics (such as mean, quartile, most common values, most recent date, ... , depending on the data type of the variable), two graphs showing the distribution of the variable, One bar chart for categorical values (if any), One bar chart for non valid values (if any), One pie chart for the proportion of valid and non-valid values (if any). The variable can be grouped using group_by parameter, which is a (categorical) column in the dataset. The user may need to use as_category() in this context. To fasten the process (and allow recycling object in a workflow) the user can feed the function with a variable_summary, which is the output of the function dataset_summarize() of the column(s) col and group_by. The summary must have the same parameters to operate.

variable_visualize(
  dataset,
  col,
  data_dict = data_dict_extract(dataset),
  group_by = attributes(variable_summary)[["madshapR_group::group_by"]],
  variable_summary = NULL,
  valueType_guess = TRUE
)

Arguments

dataset

A dataset object.

col

A character string specifying the name of the column.

data_dict

A list of data frame(s) representing metadata of the input dataset. Automatically generated if not provided.

group_by

A character string identifying the column in the dataset to use as a grouping variable. Elements will be grouped by this column.

variable_summary

A summary list which is the summary of the variables.

valueType_guess

Whether the output should include a more accurate valueType that could be applied to the dataset. TRUE by default.

Value

A list of up to seven elements (charts and figures and datatables) which can be used to summarize visualize data.

Details

A dataset is a data table containing variables. A dataset object is a data frame and can be associated with a data dictionary. If no data dictionary is provided with a dataset, a minimum workable data dictionary will be generated as needed within relevant functions. Identifier variable(s) for indexing can be specified by the user. The id values must be non-missing and will be used in functions that require it. If no identifier variable is specified, indexing is handled automatically by the function.

A data dictionary contains the list of variables in a dataset and metadata about the variables and can be associated with a dataset. A data dictionary object is a list of data frame(s) named 'Variables' (required) and 'Categories' (if any). To be usable in any function, the data frame 'Variables' must contain at least the name column, with all unique and non-missing entries, and the data frame 'Categories' must contain at least the variable and name columns, with unique combination of variable and name.

The valueType is a declared property of a variable that is required in certain functions to determine handling of the variables. Specifically, valueType refers to the OBiBa data type of a variable. The valueType is specified in a data dictionary in a column 'valueType' and can be associated with variables as attributes. Acceptable valueTypes include 'text', 'integer', 'decimal', 'boolean', datetime', 'date'. The full list of OBiBa valueType possibilities and their correspondence with R data types are available using valueType_list. The valueType can be used to coerce the variable to the corresponding data type.

Examples

# \donttest{

library(dplyr)
library(fs)

# use madshapR_examples provided by the package 
dataset <- 
  madshapR_examples$`dataset_example` %>% 
  group_by(pick('gndr')) %>% 
  as_dataset(col_id = "part_id")
  
data_dict <- madshapR_examples$`data_dictionary_example`
variable_summary <- dataset_summarize(dataset,data_dict)
#> - DATA DICTIONARY ASSESSMENT: data_dict --------------
#>     Assess the standard adequacy of naming
#>     Assess the uniqueness and presence of variable names
#>     Assess the presence of possible duplicated columns
#>     Assess the presence of duplicated rows
#>     Assess the presence of empty rows in the data dictionary
#>     Assess the presence of empty column in the data dictionary
#>     Assess the presence of categories not in the data dictionary
#>     Assess the `valueType` column in 'Variables'
#>     Assess the completion of `label:en` column in 'Variables'
#>     Assess presence and completion of `label:en` column in 'Categories'
#>     Assess the logical values of missing column in Categories
#>     Generate report
#> 
#>     The data dictionary contains no errors/warnings.
#> 
#>   - WARNING MESSAGES (if any): --------------------------------------------
#> 
#> - DATASET ASSESSMENT: dataset --------------------------
#>     Assess the standard adequacy of naming
#>     Assess the presence of variable names both in dataset and data dictionary
#>     Assess the presence of possible duplicated variable in the dataset
#>     Assess the presence of possible duplicated participants
#>     Assess the presence of unique value columns in dataset
#>     Assess the presence of empty rows in the dataset
#>     Assess the presence all empty variable in the dataset
#>     Assess the Categories comparison in dataset and data dictionary
#>     Assess the `valueType` comparison in dataset and data dictionary
#>     Generate report
#> 
#>   - WARNING MESSAGES (if any): -------------------------------------------------
#>     
#> - DATASET SUMMARIZE: dataset --------------------------
#>     Summarize the data type of each variable across the dataset
#>     Summarize information for all variables
#>     Summarize information for numerical variables
#>     Summarize information for text variables
#>     Summarize information for date variables
#>     Summarize information for categorical variables
#>     Summarize global information (Overview)
#>     Generate report
  
plots <- variable_visualize(
 dataset,data_dict, col = 'prg_ever',
 variable_summary =  variable_summary,valueType_guess = TRUE)
 
print(plots$main_values_1)
#> NULL
 
# }