The installation of T-Rx package consists of three steps:
First, you will need to download the T-Rx repository from GitHub. Open your terminal, go to the directory where you would like the repository to be stored, and clone the repository.
git clone https://github.com/chrislowh/T-Rx.git
Decompress and install R package from terminal.
# Change directory
cd T-Rx
# Decompress
tar -xzvf TRX_0.1.0.tar.gz
# Once decompressed, delete compressed version to save space
rm TRX_0.1.0.tar.gz
Open R studio, and install the package locally with the “devtools” package.
install.packages("devtools")
library(devtools)
# Install T-Rx Locally
#Note: Replace “TRX” with the absolute path of the “TRX” directory on your HPC / laptop computer:
devtools::install_local("TRX")
Note: Replace “TRX” with the absolute path of the “TRX” directory on your HPC / laptop computer.
library(TRX)
Note: You only need to load the package once.
After loading the package, you might see warnings like:
## Warning messages:
## 1: replacing previous import ‘data.table::first’ by ‘dplyr::first’ when loading ‘TRX’
## 2: replacing previous import ‘data.table::last’ by ‘dplyr::last’ when loading ‘TRX’
These warnings occur due to conflicts between functions in data.table, dplyr, and lubridate. They won’t affect the functionality but be mindful if using these functions in your own code.
You can explicitly specify the package in your calls to avoid ambiguity, e.g., data.table::first() or dplyr::first().
In the T-Rx package, several data objects were attached with functions for demonstration purposes.
‘rx_demo_1’ is a dataframe with simulated prescription records of 4 patients, containing:
Run to check the availability of data objects:
library(TRX)
# View the 'rx_demo_1' data object
head(rx_demo_1)
You should see 6 prescriptions from the first patient (ID = 1), as below:
ID | drug | class | start_date | end_date | dose | dose_unit | quantity |
---|---|---|---|---|---|---|---|
1 | fluoxetine | SSRI | 2010-02-22 | 2010-03-22 | 20 | mg | 28 |
1 | fluoxetine | SSRI | 2010-03-22 | 2010-04-19 | 20 | mg | 50 |
1 | sertraline | SSRI | 2010-04-15 | 2010-05-15 | 50 | mg | 14 |
1 | fluoxetine | SSRI | 2010-04-15 | 2010-05-15 | 20 | mg | 14 |
1 | sertraline | SSRI | 2010-05-18 | 2010-06-15 | 50 | mg | 30 |
1 | sertraline | SSRI | 2010-06-10 | 2010-07-04 | 50 | mg | 30 |
Using the demo dataset (rx_demo_1), phenotyping functions can be tested.
Here, we demonstrate creating the phenotype of antidepressant switching as an example.
Antidepressant switching is defined as changing from one antidepressant to another within a specific time frame, suggesting non-response or adverse effects. For details, please refer to the paper here.
To identify switchers in a dataframe of prescriptions:
library(TRX)
switch = switch_Lo2025(
df = rx_demo_1,
id_col = "ID", name_col = "drug", class_col = "class", date_col = "start_date",
time_switch = 90, nudge_days = 5,
pre_switch_count = 2, post_switch_count = 2, total_count = 3,
identify_controls = FALSE)
print(switch)
Note: The phenotyping functions are named after the following convention:
You should see the following data frame (2 rows, 8 columns):
pt_id | cc | pre_drug | pre_class | switch_time | post_drug | post_class | index_date |
---|---|---|---|---|---|---|---|
1 | case | fluoxetine | SSRI | 52 | sertraline | SSRI | 2010-02-22 |
4 | case | citalopram | SSRI | 63 | fluoxetine | SSRI | 2009-12-24 |
This shows that six prescriptions from patient 1 (pt_id = 1) are summarised into a single row, indicating a switch from fluoxetine (SSRI) to sertraline (SSRI) with a switch time of 52 days.
The package also allows for identifying other phenotypes, with more information found here.
Please post questions as an issue on the T-Rx GitHub repo here.
The T-Rx package is currently under beta testing. Most functions should have adequate documentation on possible errors.
Please kindly reach out to Chris Lo (chris.lowh@kcl.ac.uk) for feedback on documentation.