Learn R Programming

dmtools

Installation

install.packages("dmtools")

# dev-version
devtools::install_github("KonstantinRyabov/dmtools")

library(dmtools)

Overview

For checking the dataset from EDC in clinical trials. Notice, your dataset should have a postfix( _V1 ) or a prefix( V1_ ) in the names of variables. Column names should be unique.

  • date() - create object date to check dates in the dataset
  • lab() - create object lab to check lab reference range
  • short() - create object short to reshape the dataset in a tidy view.
  • check() - check objects
  • get_result() - get the final result of object
  • choose_test() - filter the final result of check()
  • rename_dataset() - rename the dataset

Usage

For example, you want to check laboratory values, you need to create the excel table like in the example.

  • AGELOW - number, >= number
  • AGEHIGH - if none, type Inf, <= number
  • SEX - for both sex, use |
  • LBTEST - What was the lab test name? (can be any convenient name for you)
  • LBORRES* - What was the result of the lab test?
  • LBNRIND* - How [did/do] the reported values compare within the [reference/normal/expected] range?
  • LBORNRLO - What was the lower limit of the reference range for this lab test, >=
  • LBORNRHI - What was the high limit of the reference range for this lab test, <=

*column names without prefix or postfix

# "norm" and "no" it is an example, necessary variable for the estimate, get from the dataset
refs <- system.file("labs_refer.xlsx", package = "dmtools")
obj_lab <- lab(refs, ID, AGE, SEX, "norm", "no")
obj_lab <- obj_lab %>% check(df)

# ok - analysis, which has a correct estimate of the result
obj_lab %>% choose_test("ok")
#>   ID AGE SEX                 LBTEST LBTESTCD VISIT LBORNRLO LBORNRHI LBORRES
#> 1 01  19   f                Glucose     GLUC   _V1      3.9      5.9     5.5
#> 2 01  19   f Aspartate transaminase      AST   _V2      0.0     39.0      30
#> 3 03  22   m Aspartate transaminase      AST   _V2      0.0     42.0      31
#>   LBNRIND RES_TYPE_NUM IND_EXPECTED
#> 1    norm          5.5         norm
#> 2    norm         30.0         norm
#> 3    norm         31.0         norm

# mis - analysis, which has an incorrect estimate of the result
obj_lab %>% choose_test("mis")
#>   ID AGE SEX                 LBTEST LBTESTCD VISIT LBORNRLO LBORNRHI LBORRES
#> 1 02  20   m Aspartate transaminase      AST   _V2      0.0     42.0      48
#> 2 03  22   m                Glucose     GLUC   _V1      3.9      5.9     9.7
#>   LBNRIND RES_TYPE_NUM IND_EXPECTED
#> 1    norm         48.0           no
#> 2    norm          9.7           no

# skip - analysis, which has an empty value of the estimate
obj_lab %>% choose_test("skip")
#>   ID AGE SEX  LBTEST LBTESTCD VISIT LBORNRLO LBORNRHI LBORRES LBNRIND
#> 1 02  20   m Glucose     GLUC   _V1      3.9      5.9     4.1    <NA>
#>   RES_TYPE_NUM IND_EXPECTED
#> 1          4.1         norm
# dmtools can work with the dataset as strange_df
# parameter is_post has value FALSE because a dataset has a prefix( V1_ ) in the names of variables
obj_lab <- lab(refs, ID, AGE, SEX, "norm", "no", is_post = F)
obj_lab <- obj_lab %>% check(strange_df)

# dmtools can understand the value with a comma like 6,6 
obj_lab %>% choose_test("ok")
#>   ID AGE SEX                 LBTEST LBTESTCD VISIT LBORNRLO LBORNRHI LBORRES
#> 1 01  19   f                Glucose     GLUC   V1_      3.9      5.9     5,5
#> 2 03  22   m Aspartate transaminase      AST   V2_      0.0     42.0      31
#>   LBNRIND RES_TYPE_NUM IND_EXPECTED
#> 1    norm          5.5         norm
#> 2    norm         31.0         norm

# Notice, if dmtools can't understand the value of lab_vals e.g. < 5, it puts Inf in the RES_TYPE_NUM
obj_lab %>% choose_test("mis")
#>   ID AGE SEX                 LBTEST LBTESTCD VISIT LBORNRLO LBORNRHI LBORRES
#> 1 01  19   f Aspartate transaminase      AST   V2_      0.0     39.0     < 5
#> 2 02  20   m Aspartate transaminase      AST   V2_      0.0     42.0      48
#> 3 03  22   m                Glucose     GLUC   V1_      3.9      5.9     9,7
#>   LBNRIND RES_TYPE_NUM IND_EXPECTED
#> 1    norm          Inf           no
#> 2    norm         48.0           no
#> 3    norm          9.7           no

obj_lab %>% choose_test("skip")
#>   ID AGE SEX  LBTEST LBTESTCD VISIT LBORNRLO LBORNRHI LBORRES LBNRIND
#> 1 02  20   m Glucose     GLUC   V1_      3.9      5.9     4,1    <NA>
#>   RES_TYPE_NUM IND_EXPECTED
#> 1          4.1         norm

Copy Link

Version

Install

install.packages('dmtools')

Monthly Downloads

208

Version

0.2.6

License

MIT + file LICENSE

Issues

Pull Requests

Stars

Forks

Maintainer

Konstantin Ryabov

Last Published

November 8th, 2020

Functions in dmtools (0.2.6)

find_colnames.default

Find column names
get_result

Get the final result of the check
meddra_auth

Get the token
meddra_post

Create the post query
to_long.short

Reshape the dataset to a long view
to_long

Reshape the dataset to a long view
to_dbl

Cast to double type
lab

Create object lab
list_parse

A list to a tibble.
short

Create object short
rename_dataset

For rename dataset
check

Check the dataset
find_colnames.date

Find column names with dates
find_colnames

Find column names
to_long.date

Reshape the dataset to a long view
check.default

Check the dataset
to_long.lab

Reshape the dataset to a long view
dmtools

dmtools: package to validate data
calc_diff

Function for calculating the difference between two dates
choose_test.date

Filter the final result of the object date
create_spec

For creating part of the specification
choose_test

Filter the final result
choose_test.lab

Filter the final result of the object lab
date

Create object date
add_cols

Add columns if columns don't exist