Title: | Tools for Clinical Data Management |
---|---|
Description: | For checking the dataset from EDC(Electronic Data Capture) in clinical trials. 'dmtools' reshape your dataset in a tidy view and check events. You can reshape the dataset and choose your target to check, for example, the laboratory reference range. |
Authors: | Konstantin Ryabov [aut, cre] |
Maintainer: | Konstantin Ryabov <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.2.6.9000 |
Built: | 2024-10-27 03:03:48 UTC |
Source: | https://github.com/konstantinryabov/dmtools |
Add columns if columns don't exist
add_cols(dset, ds_part, target_cols)
add_cols(dset, ds_part, target_cols)
dset |
A data frame. The dataset. |
ds_part |
A character scalar. Prefix or postfix. |
target_cols |
A character vector with necessary columns. |
A data frame. The dataset.
Function for calculating the difference between two dates
calc_diff(st_inter, dt_item)
calc_diff(st_inter, dt_item)
st_inter |
An interval. An object of interval. |
dt_item |
A date item. An object of date. |
An integer scalar. Differences between the two dates.
Check the dataset
check(obj, dataset)
check(obj, dataset)
obj |
An object for check. |
dataset |
A dataset, a type is a data frame. |
An object with a check result.
id <- c("01", "02", "03") screen_date_E1 <- c("1991-03-13", "1991-03-07", "1991-03-08") rand_date_E2 <- c("1991-03-15", "1991-03-11", "1991-03-10") ph_date_E3 <- c("1991-03-21", "1991-03-16", "1991-03-16") bio_date_E3 <- c("1991-03-23", "1991-03-16", "1991-03-16") df <- data.frame(id, screen_date_E1, rand_date_E2, ph_date_E3, bio_date_E3, stringsAsFactors = FALSE ) timeline <- system.file("dates.xlsx", package = "dmtools") obj_date <- date(timeline, id, dplyr::contains) obj_date <- check(obj_date, df)
id <- c("01", "02", "03") screen_date_E1 <- c("1991-03-13", "1991-03-07", "1991-03-08") rand_date_E2 <- c("1991-03-15", "1991-03-11", "1991-03-10") ph_date_E3 <- c("1991-03-21", "1991-03-16", "1991-03-16") bio_date_E3 <- c("1991-03-23", "1991-03-16", "1991-03-16") df <- data.frame(id, screen_date_E1, rand_date_E2, ph_date_E3, bio_date_E3, stringsAsFactors = FALSE ) timeline <- system.file("dates.xlsx", package = "dmtools") obj_date <- date(timeline, id, dplyr::contains) obj_date <- check(obj_date, df)
Check the dataset
## Default S3 method: check(obj, dataset)
## Default S3 method: check(obj, dataset)
obj |
An object for check. |
dataset |
A dataset, a type is a data frame. |
An object with a check result.
id <- c("01", "02", "03") screen_date_E1 <- c("1991-03-13", "1991-03-07", "1991-03-08") rand_date_E2 <- c("1991-03-15", "1991-03-11", "1991-03-10") ph_date_E3 <- c("1991-03-21", "1991-03-16", "1991-03-16") bio_date_E3 <- c("1991-03-23", "1991-03-16", "1991-03-16") df <- data.frame(id, screen_date_E1, rand_date_E2, ph_date_E3, bio_date_E3, stringsAsFactors = FALSE ) timeline <- system.file("dates.xlsx", package = "dmtools") obj_date <- date(timeline, id, dplyr::contains) obj_date <- check(obj_date, df)
id <- c("01", "02", "03") screen_date_E1 <- c("1991-03-13", "1991-03-07", "1991-03-08") rand_date_E2 <- c("1991-03-15", "1991-03-11", "1991-03-10") ph_date_E3 <- c("1991-03-21", "1991-03-16", "1991-03-16") bio_date_E3 <- c("1991-03-23", "1991-03-16", "1991-03-16") df <- data.frame(id, screen_date_E1, rand_date_E2, ph_date_E3, bio_date_E3, stringsAsFactors = FALSE ) timeline <- system.file("dates.xlsx", package = "dmtools") obj_date <- date(timeline, id, dplyr::contains) obj_date <- check(obj_date, df)
Filter the final result
choose_test(obj, test, group_id)
choose_test(obj, test, group_id)
obj |
An object for check. |
test |
Parameters, which use to filter the final dataset. |
group_id |
A logical scalar, default is TRUE.True is grouped by id, otherwise, it isn't grouped. |
The filtered dataset.
id <- c("01", "02", "03") screen_date_E1 <- c("1991-03-13", "1991-03-07", "1991-03-08") rand_date_E2 <- c("1991-03-15", "1991-03-11", "1991-03-10") ph_date_E3 <- c("1991-03-21", "1991-03-16", "1991-03-16") bio_date_E3 <- c("1991-03-23", "1991-03-16", "1991-03-16") df <- data.frame(id, screen_date_E1, rand_date_E2, ph_date_E3, bio_date_E3, stringsAsFactors = FALSE ) timeline <- system.file("dates.xlsx", package = "dmtools") obj_date <- date(timeline, id, dplyr::contains) obj_date <- check(obj_date, df) choose_test(obj_date, "out")
id <- c("01", "02", "03") screen_date_E1 <- c("1991-03-13", "1991-03-07", "1991-03-08") rand_date_E2 <- c("1991-03-15", "1991-03-11", "1991-03-10") ph_date_E3 <- c("1991-03-21", "1991-03-16", "1991-03-16") bio_date_E3 <- c("1991-03-23", "1991-03-16", "1991-03-16") df <- data.frame(id, screen_date_E1, rand_date_E2, ph_date_E3, bio_date_E3, stringsAsFactors = FALSE ) timeline <- system.file("dates.xlsx", package = "dmtools") obj_date <- date(timeline, id, dplyr::contains) obj_date <- check(obj_date, df) choose_test(obj_date, "out")
Filter the final result of the object date
## S3 method for class 'date' choose_test(obj, test = "out", group_id = T)
## S3 method for class 'date' choose_test(obj, test = "out", group_id = T)
obj |
An object for calculation. Class date. |
test |
A character scalar. Parameters, which use to filter the final dataset, default: "out": "out" - dates, which are out of the protocol's timeline, "uneq" - dates, which are unequal, "ok" - correct dates, "skip" - empty dates. |
group_id |
A logical scalar, default is TRUE.True is grouped by id, otherwise, it isn't grouped. |
The dataset by a value of test
.
id <- c("01", "02", "03") screen_date_E1 <- c("1991-03-13", "1991-03-07", "1991-03-08") rand_date_E2 <- c("1991-03-15", "1991-03-11", "1991-03-10") ph_date_E3 <- c("1991-03-21", "1991-03-16", "1991-03-16") bio_date_E3 <- c("1991-03-23", "1991-03-16", "1991-03-16") df <- data.frame(id, screen_date_E1, rand_date_E2, ph_date_E3, bio_date_E3, stringsAsFactors = FALSE ) timeline <- system.file("dates.xlsx", package = "dmtools") obj_date <- date(timeline, id, dplyr::contains) obj_date <- check(obj_date, df) choose_test(obj_date, "out")
id <- c("01", "02", "03") screen_date_E1 <- c("1991-03-13", "1991-03-07", "1991-03-08") rand_date_E2 <- c("1991-03-15", "1991-03-11", "1991-03-10") ph_date_E3 <- c("1991-03-21", "1991-03-16", "1991-03-16") bio_date_E3 <- c("1991-03-23", "1991-03-16", "1991-03-16") df <- data.frame(id, screen_date_E1, rand_date_E2, ph_date_E3, bio_date_E3, stringsAsFactors = FALSE ) timeline <- system.file("dates.xlsx", package = "dmtools") obj_date <- date(timeline, id, dplyr::contains) obj_date <- check(obj_date, df) choose_test(obj_date, "out")
Filter the final result of the object lab
## S3 method for class 'lab' choose_test(obj, test = "mis", group_id = T)
## S3 method for class 'lab' choose_test(obj, test = "mis", group_id = T)
obj |
An object. Class lab. |
test |
A character scalar. Parameters, which use to filter the final dataset, default: "mis": "ok" - analysis, which has a correct estimate of the result, "mis" - analysis, which has an incorrect estimate of the result, "skip" - analysis, which has an empty value of the estimate, "null" - analysis, which has an empty result and value of the estimate. |
group_id |
A logical scalar, default is TRUE.True is grouped by id, otherwise, it isn't grouped. |
The filtered dataset by a value of test
.
ID <- c("01", "02", "03") SITE <- c("site 01", "site 02", "site 03") AGE <- c("19", "20", "22") SEX <- c("f", "m", "f") GLUC_V1 <- c(5.5, 4.1, 9.7) GLUC_IND_V1 <- c("norm", "no", "cl") AST_V2 <- c("30", "48", "31") AST_IND_V2 <- c(NA, "norm", "norm") df <- data.frame( ID, SITE, AGE, SEX, GLUC_V1, GLUC_IND_V1, AST_V2, AST_IND_V2, stringsAsFactors = FALSE ) refs <- system.file("labs_refer.xlsx", package = "dmtools") obj_lab <- lab(refs, ID, AGE, SEX, "norm", "no") obj_lab <- check(obj_lab, df) choose_test(obj_lab, "mis")
ID <- c("01", "02", "03") SITE <- c("site 01", "site 02", "site 03") AGE <- c("19", "20", "22") SEX <- c("f", "m", "f") GLUC_V1 <- c(5.5, 4.1, 9.7) GLUC_IND_V1 <- c("norm", "no", "cl") AST_V2 <- c("30", "48", "31") AST_IND_V2 <- c(NA, "norm", "norm") df <- data.frame( ID, SITE, AGE, SEX, GLUC_V1, GLUC_IND_V1, AST_V2, AST_IND_V2, stringsAsFactors = FALSE ) refs <- system.file("labs_refer.xlsx", package = "dmtools") obj_lab <- lab(refs, ID, AGE, SEX, "norm", "no") obj_lab <- check(obj_lab, df) choose_test(obj_lab, "mis")
For creating part of the specification
create_spec(df_spec, all_colname, part_spec, is_pst)
create_spec(df_spec, all_colname, part_spec, is_pst)
df_spec |
A dataset, a type is a data frame. |
all_colname |
A character vector with all names in the dataset. |
part_spec |
A character scalar. Prefixes or postfixes. |
is_pst |
A logical scalar, default is TRUE. True is postfix, otherwise, prefix. |
A data frame. Part of the specification.
Create object date
date(file, id, get_visit, get_date = dplyr::contains, str_date = "DAT")
date(file, id, get_visit, get_date = dplyr::contains, str_date = "DAT")
file |
A character scalar. Path to the date's parameters in the excel table. |
id |
A column name of the subject id in the dataset, without quotes. |
get_visit |
A function, which select necessary visit or event e.g. dplyr::start_with, dplyr::contains. |
get_date |
A function, which select dates from necessary visit e.g. dplyr::matches, dplyr::contains, default: dplyr::contains. |
str_date |
A date's pattern in column names, default: "DAT". |
The object date.
obj_date <- date("dates.xlsx", id, dplyr::contains) obj_date <- date("dates.xlsx", id, dplyr::contains, "uneq")
obj_date <- date("dates.xlsx", id, dplyr::contains) obj_date <- date("dates.xlsx", id, dplyr::contains, "uneq")
Find column names
find_colnames(obj, dataset, row_file)
find_colnames(obj, dataset, row_file)
obj |
An object for check. |
dataset |
A dataset, a type is a data frame. |
row_file |
A row of the file. |
A data frame. Result of run_tests.
Find column names with dates
## S3 method for class 'date' find_colnames(obj, dataset, row_file)
## S3 method for class 'date' find_colnames(obj, dataset, row_file)
obj |
An object for validation. |
dataset |
A data frame. Class date. |
row_file |
A data frame. A data frame with analysis parameters. |
A data frame. Visit's dates.
Find column names
## Default S3 method: find_colnames(obj, dataset, row_file)
## Default S3 method: find_colnames(obj, dataset, row_file)
obj |
An object for validation. |
dataset |
A dataset, a type is a data frame. |
row_file |
A row of the file. |
A data frame. Result of run_tests.
Get the final result of the check
get_result(obj, group_id = T)
get_result(obj, group_id = T)
obj |
An object. Can be all classes: short, lab, date. |
group_id |
A logical scalar, default is TRUE.True is grouped by id, otherwise, it isn't grouped. |
A data frame. The final result.
id <- c("01", "02", "03") site <- c("site 01", "site 02", "site 03") sex <- c("f", "m", "f") preg_yn_e2 <- c("y", "y", "y") preg_res_e2 <- c("neg", "neg", "neg") preg_yn_e3 <- c("y", "y", "n") preg_res_e3 <- c("neg", "pos", "unnes") df <- data.frame( id, site, sex, preg_yn_e2, preg_res_e2, preg_yn_e3, preg_res_e3, stringsAsFactors = FALSE ) preg <- system.file("preg.xlsx", package = "dmtools") obj_short <- short(preg, id, "LBORRES", c("site", "sex")) obj_short <- check(obj_short, df) get_result(obj_short)
id <- c("01", "02", "03") site <- c("site 01", "site 02", "site 03") sex <- c("f", "m", "f") preg_yn_e2 <- c("y", "y", "y") preg_res_e2 <- c("neg", "neg", "neg") preg_yn_e3 <- c("y", "y", "n") preg_res_e3 <- c("neg", "pos", "unnes") df <- data.frame( id, site, sex, preg_yn_e2, preg_res_e2, preg_yn_e3, preg_res_e3, stringsAsFactors = FALSE ) preg <- system.file("preg.xlsx", package = "dmtools") obj_short <- short(preg, id, "LBORRES", c("site", "sex")) obj_short <- check(obj_short, df) get_result(obj_short)
Create object lab
lab( file, id, age, sex, normal, abnormal, is_post = T, name_to_find = "LBNRIND" )
lab( file, id, age, sex, normal, abnormal, is_post = T, name_to_find = "LBNRIND" )
file |
A character scalar. Path to the laboratory's reference in the excel table. |
id |
A column name of the subject id in the dataset, without quotes. |
age |
A column name of the subject age in the dataset, without quotes. |
sex |
A column name of the subject sex in the dataset, without quotes. |
normal |
A normal estimate, for example, "NORMAL". |
abnormal |
An abnormal estimate, for example, "ABNORMAL". |
is_post |
A logical scalar, default is TRUE. True is postfix, otherwise, prefix. |
name_to_find |
A character scalar. For search prefixes or postfixes, default is "LBNRIND". |
The object lab.
obj_lab <- lab("lab_refer.xlsx", ID, AGE, SEX, 1, 2) obj_lab <- lab("lab_refer.xlsx", ID, AGE, SEX, "NORMAL", "ABNORMAL") obj_lab <- lab("lab_refer.xlsx", ID, AGE, SEX, "norm", "no", FALSE)
obj_lab <- lab("lab_refer.xlsx", ID, AGE, SEX, 1, 2) obj_lab <- lab("lab_refer.xlsx", ID, AGE, SEX, "NORMAL", "ABNORMAL") obj_lab <- lab("lab_refer.xlsx", ID, AGE, SEX, "norm", "no", FALSE)
A list to a tibble.
list_parse(to_tibble)
list_parse(to_tibble)
to_tibble |
A list with nested lists. |
A tibble.
temp_list <- list(list(a = 1, b = 3), list(a = 4, b = 5)) list_parse(temp_list)
temp_list <- list(list(a = 1, b = 3), list(a = 4, b = 5)) list_parse(temp_list)
Get the token
meddra_auth(target_url, meddra_id, api_key)
meddra_auth(target_url, meddra_id, api_key)
target_url |
The url for authenticate. |
meddra_id |
The user's meddra id. |
api_key |
The user's api key. |
A string scalar. The user's token.
## Not run: meddra_auth(url, id, key) ## End(Not run)
## Not run: meddra_auth(url, id, key) ## End(Not run)
Create the post query
meddra_post(target_url, json, token)
meddra_post(target_url, json, token)
target_url |
The url for a post query. |
json |
A string scalar or a list. The json query. |
token |
The user's token. |
A list. The result of query.
## Not run: meddra_post(url, json_body, token) ## End(Not run)
## Not run: meddra_post(url, json_body, token) ## End(Not run)
For rename dataset
rename_dataset( dataset, path_crfs, no_readable_name, readable_name, num_sheet = 1, extension = "*.xlsx", is_post = T )
rename_dataset( dataset, path_crfs, no_readable_name, readable_name, num_sheet = 1, extension = "*.xlsx", is_post = T )
dataset |
A dataset, a type is a data frame. |
path_crfs |
A character scalar. Path to the specification files the in excel table. |
no_readable_name |
A character scalar. A column name of no_readable values. |
readable_name |
A character scalar. A column name of readable values. |
num_sheet |
An integer scalar, default is the first sheet. A position of a sheet in the excel document. |
extension |
A character scalar. A extension of files, default is *.xlsx. |
is_post |
A logical scalar, default is TRUE. True is postfix, otherwise, prefix. |
The list with two values: data - renamed dataset, spec - common specification. The common specification is data frame of two values: no_readable_var, readable_var.
id <- c("01", "02", "03") age <- c("19", "20", "22") sex <- c("f", "m", "f") bio_date_post <- c("1991-03-23", "1991-03-16", "1991-03-16") gluc_post <- c("5.5", "4.1", "9.7") gluc_res_post <- c("norm", "no", "norm") df <- data.frame( id, age, sex, bio_date_post, gluc_post, gluc_res_post, stringsAsFactors = FALSE ) crfs <- system.file("forms", package = "dmtools") result <- rename_dataset(df, crfs, "old_name", "new_name") result[["data"]]
id <- c("01", "02", "03") age <- c("19", "20", "22") sex <- c("f", "m", "f") bio_date_post <- c("1991-03-23", "1991-03-16", "1991-03-16") gluc_post <- c("5.5", "4.1", "9.7") gluc_res_post <- c("norm", "no", "norm") df <- data.frame( id, age, sex, bio_date_post, gluc_post, gluc_res_post, stringsAsFactors = FALSE ) crfs <- system.file("forms", package = "dmtools") result <- rename_dataset(df, crfs, "old_name", "new_name") result[["data"]]
Create object short
short( file, id, name_to_find, common_cols = NULL, extra = NULL, is_post = T, is_add_cols = F )
short( file, id, name_to_find, common_cols = NULL, extra = NULL, is_post = T, is_add_cols = F )
file |
A character scalar. Path to the excel table. |
id |
A column name of the subject id in the dataset, without quotes. |
name_to_find |
A character scalar. For search prefixes or postfixes. |
common_cols |
A character vector. A column names in the dataset, which common for all events. |
extra |
A character scalar. For additional information. |
is_post |
A logical scalar, default is TRUE. True is postfix, otherwise, prefix. |
is_add_cols |
A logical scalar, default is FALSE. If necessary add columns. |
The object short.
obj_short <- short("preg.xlsx", id, "res", c("site", "sex")) obj_short <- short("labs.xlsx", id, "name_labs", c("site"), "human_name")
obj_short <- short("preg.xlsx", id, "res", c("site", "sex")) obj_short <- short("labs.xlsx", id, "name_labs", c("site"), "human_name")
Cast to double type
to_dbl(vals)
to_dbl(vals)
vals |
A character or double vector. |
A double vector.
Reshape the dataset to a long view
to_long(obj, dataset, row_file, part)
to_long(obj, dataset, row_file, part)
obj |
An object for check. |
dataset |
A data frame. |
row_file |
A data frame. A data frame with parameters. |
part |
A character scalar. Prefixes or postfixes. |
A data frame. The part of final result.
Reshape the dataset to a long view
## S3 method for class 'date' to_long(obj, dataset, row_file, date)
## S3 method for class 'date' to_long(obj, dataset, row_file, date)
obj |
An object for validation. |
dataset |
A data frame. Class date. |
row_file |
A data frame. A data frame with analysis parameters. |
date |
A column name with dates. |
A data frame. Result of the date's validation.
Reshape the dataset to a long view
## S3 method for class 'lab' to_long(obj, dataset, row_file, part)
## S3 method for class 'lab' to_long(obj, dataset, row_file, part)
obj |
An object. Class lab. |
dataset |
A data frame. |
row_file |
A data frame. A data frame with parameters. |
part |
A character scalar. Prefixes or postfixes. |
A data frame. The part of the final result.
Reshape the dataset to a long view
## S3 method for class 'short' to_long(obj, dataset, row_file, part)
## S3 method for class 'short' to_long(obj, dataset, row_file, part)
obj |
An object. Class short. |
dataset |
A data frame. |
row_file |
A data frame. A data frame with parameters. |
part |
A character scalar. Prefixes or postfixes. |
A data frame. The part of the final result.