View source: R/prep_prepare_dataframes.R
prep_prepare_dataframes | R Documentation |
This function ensures, that a data frame ds1
with suitable variable
names study_data and meta_data exist as base data.frames.
prep_prepare_dataframes(
.study_data,
.meta_data,
.label_col,
.replace_hard_limits,
.replace_missings,
.sm_code = NULL,
.allow_empty = FALSE,
.adjust_data_type = TRUE,
.amend_scale_level = TRUE,
.internal = rlang::env_inherits(rlang::caller_env(), parent.env(environment()))
)
.study_data |
if provided, use this data set as study_data |
.meta_data |
if provided, use this data set as meta_data |
.label_col |
if provided, use this as label_col |
.replace_hard_limits |
replace |
.replace_missings |
replace missing codes, defaults to |
.sm_code |
missing code for |
.allow_empty |
allow |
.adjust_data_type |
ensure that the data type of variables in the study data corresponds to their data type specified in the metadata |
.amend_scale_level |
ensure that |
.internal |
logical internally called, modify caller's environment. |
This function defines ds1
and modifies study_data
and meta_data
in the
environment of its caller (see eval.parent). It also defines or modifies
the object label_col
in the calling environment. Almost all functions
exported by dataquieR
call this function initially, so that aspects common
to all functions live here, e.g. testing, if an argument meta_data
has been
given and features really a data.frame. It verifies the existence of
required metadata attributes (VARATT_REQUIRE_LEVELS). It can also replace
missing codes by NA
s, and calls prep_study2meta to generate a minimum
set of metadata from the study data on the fly (should be amended, so
on-the-fly-calling is not recommended for an instructive use of dataquieR
).
The function also detects tibbles
, which are then converted to base-R
data.frames, which are expected by dataquieR
.
Different from the other utility function that work
in the caller's environment, so it modifies objects in the calling function.
It defines a new object ds1
, it modifies study_data
and/or meta_data
and label_col
, if .internal
is TRUE
.
ds1
the study data with mapped column names
acc_margins
## Not run:
acc_test1 <- function(resp_variable, aux_variable,
time_variable, co_variables,
group_vars, study_data, meta_data) {
prep_prepare_dataframes()
invisible(ds1)
}
acc_test2 <- function(resp_variable, aux_variable,
time_variable, co_variables,
group_vars, study_data, meta_data, label_col) {
ds1 <- prep_prepare_dataframes(study_data, meta_data)
invisible(ds1)
}
environment(acc_test1) <- asNamespace("dataquieR")
# perform this inside the package (not needed for functions that have been
# integrated with the package already)
environment(acc_test2) <- asNamespace("dataquieR")
# perform this inside the package (not needed for functions that have been
# integrated with the package already)
acc_test3 <- function(resp_variable, aux_variable, time_variable,
co_variables, group_vars, study_data, meta_data,
label_col) {
prep_prepare_dataframes()
invisible(ds1)
}
acc_test4 <- function(resp_variable, aux_variable, time_variable,
co_variables, group_vars, study_data, meta_data,
label_col) {
ds1 <- prep_prepare_dataframes(study_data, meta_data)
invisible(ds1)
}
environment(acc_test3) <- asNamespace("dataquieR")
# perform this inside the package (not needed for functions that have been
# integrated with the package already)
environment(acc_test4) <- asNamespace("dataquieR")
# perform this inside the package (not needed for functions that have been
# integrated with the package already)
load(system.file("extdata/meta_data.RData", package = "dataquieR"))
load(system.file("extdata/study_data.RData", package = "dataquieR"))
try(acc_test1())
try(acc_test2())
acc_test1(study_data = study_data)
try(acc_test1(meta_data = meta_data))
try(acc_test2(study_data = 12, meta_data = meta_data))
print(head(acc_test1(study_data = study_data, meta_data = meta_data)))
print(head(acc_test2(study_data = study_data, meta_data = meta_data)))
print(head(acc_test3(study_data = study_data, meta_data = meta_data)))
print(head(acc_test3(study_data = study_data, meta_data = meta_data,
label_col = LABEL)))
print(head(acc_test4(study_data = study_data, meta_data = meta_data)))
print(head(acc_test4(study_data = study_data, meta_data = meta_data,
label_col = LABEL)))
try(acc_test2(study_data = NULL, meta_data = meta_data))
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.