R/03-dataset_functions.R
dossier_create.Rd
Generates a dossier object (list of one or more datasets).
dossier_create(dataset_list, data_dict_apply = FALSE)
A list of data frame, each of them being dataset object.
Whether data dictionary(ies) should be applied to associated dataset(s), creating labelled dataset(s) with variable attributes. Any previous attributes will be preserved. FALSE by default.
A list of data frame(s), containing input dataset(s).
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.
{
# use madshapR_DEMO provided by the package
library(dplyr)
###### Example 1: datasets can be gathered into a dossier which is a list.
dossier <- dossier_create(
dataset_list = list(
dataset_MELBOURNE = madshapR_DEMO$dataset_MELBOURNE,
dataset_PARIS = madshapR_DEMO$dataset_PARIS ))
glimpse(dossier)
###### Example 2: Any data frame can be gathered into a dossier
glimpse(dossier_create(list(iris, mtcars)))
}
#> List of 2
#> $ dataset_MELBOURNE: tibble [19 × 6] (S3: tbl_df/tbl/data.frame)
#> ..$ id : num [1:19] 377943 497013 927676 995667 21829 ...
#> ..$ Gender : num [1:19] 2 1 1 2 2 1 2 2 2 1 ...
#> ..$ BMI : num [1:19] 22.1 18.5 24.6 15.7 18.6 ...
#> ..$ age : num [1:19] 52 49 43 59 40 47 -888 53 35 40 ...
#> ..$ smo_status: num [1:19] 1 2 3 -77 NA 2 -77 2 1 1 ...
#> ..$ prg_curr : num [1:19] 0 -77 -77 1 0 -77 8 0 0 -77 ...
#> ..- attr(*, "madshapR::class")= chr "dataset"
#> $ dataset_PARIS : tibble [24 × 7] (S3: tbl_df/tbl/data.frame)
#> ..$ ID : chr [1:24] "Paris_687393" "Paris_585666" "Paris_75802" "Paris_412072" ...
#> ..$ SEX : num [1:24] 1 0 0 1 1 0 1 1 1 0 ...
#> ..$ BMI : num [1:24] 22.2 15.2 22.7 NA 26.2 ...
#> ..$ AGE : num [1:24] 52 49 43 59 40 47 46 53 35 NA ...
#> ..$ SMO : num [1:24] 1 1 1 1 1 1 1 0 1 0 ...
#> ..$ SMO_QTY : num [1:24] 32 8 48 11 18 7 18 -8 36 -8 ...
#> ..$ PRG_EVER: num [1:24] 0 -8 -8 0 1 -8 NA 1 1 -8 ...
#> ..- attr(*, "madshapR::class")= chr "dataset"
#> - attr(*, "madshapR::class")= chr "dossier"
#> List of 2
#> $ iris :'data.frame': 150 obs. of 5 variables:
#> ..$ Sepal.Length: num [1:150] 5.1 4.9 4.7 4.6 5 5.4 4.6 5 4.4 4.9 ...
#> ..$ Sepal.Width : num [1:150] 3.5 3 3.2 3.1 3.6 3.9 3.4 3.4 2.9 3.1 ...
#> ..$ Petal.Length: num [1:150] 1.4 1.4 1.3 1.5 1.4 1.7 1.4 1.5 1.4 1.5 ...
#> ..$ Petal.Width : num [1:150] 0.2 0.2 0.2 0.2 0.2 0.4 0.3 0.2 0.2 0.1 ...
#> ..$ Species : Factor w/ 3 levels "setosa","versicolor",..: 1 1 1 1 1 1 1 1 1 1 ...
#> ..- attr(*, "madshapR::class")= chr "dataset"
#> $ mtcars:'data.frame': 32 obs. of 11 variables:
#> ..$ mpg : num [1:32] 21 21 22.8 21.4 18.7 18.1 14.3 24.4 22.8 19.2 ...
#> ..$ cyl : num [1:32] 6 6 4 6 8 6 8 4 4 6 ...
#> ..$ disp: num [1:32] 160 160 108 258 360 ...
#> ..$ hp : num [1:32] 110 110 93 110 175 105 245 62 95 123 ...
#> ..$ drat: num [1:32] 3.9 3.9 3.85 3.08 3.15 2.76 3.21 3.69 3.92 3.92 ...
#> ..$ wt : num [1:32] 2.62 2.88 2.32 3.21 3.44 ...
#> ..$ qsec: num [1:32] 16.5 17 18.6 19.4 17 ...
#> ..$ vs : num [1:32] 0 0 1 1 0 1 0 1 1 1 ...
#> ..$ am : num [1:32] 1 1 1 0 0 0 0 0 0 0 ...
#> ..$ gear: num [1:32] 4 4 4 3 3 3 3 4 4 4 ...
#> ..$ carb: num [1:32] 4 4 1 1 2 1 4 2 2 4 ...
#> ..- attr(*, "madshapR::class")= chr "dataset"
#> - attr(*, "madshapR::class")= chr "dossier"