knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
library(tidyverse) library(sentinelreadr) library(logr) logfile <- file.path(Sys.getenv("HOME"),paste0("sentinelreadr_",gsub("([ ]|:|-)","_",Sys.time()))) lf <- logr::log_open(logfile)
This is a small package that simplifies the extraction of the data that is stored in xml inside RSNTL file. At the present there are three main function
input_filename <- system.file("extdata","2013_B_07-01-2021_13-49-43.RSNTL",package="sentinelreadr") xml <- read_rsntl(input_filename,chkDMV=T)
The test data section can be decoded to a tibble. Because the xml object returned buy the read_rstnl() funtion is a list of lists it is best to use the lapply function to the various items in the xml object
is(xml) summary(xml) lapply(xml,is)
patient <- lapply(xml$test_details,testdetails_xml_to_table,trans=T) DT::datatable(patient[[1]])
The summary shows that there are two datasets in this file
data <- lapply(xml$clinical_data,clinical_xml_to_table) DT::datatable(data[[1]])
However it appears they are the same data
DT::datatable(data[[2]])
This data is plotable
library(ggplot2) gg <- ggplot(data[[2]],aes(x=Time,y=Systolic)) + geom_point(colour="blue") plot(gg)
Reading the other files
input_filename <- system.file("extdata","2014_B_07-01-2021_13-49-44.RSNTL",package="sentinelreadr") xml <- read_rsntl(input_filename,chkDMV=T)
Get test details
patient <- lapply(xml$test_details,testdetails_xml_to_table) DT::datatable(patient[[1]])
Get data details
data <- lapply(xml$clinical_data,clinical_xml_to_table) DT::datatable(data[[1]])
Read file 3
input_filename <- system.file("extdata","2011_B_07-01-2021_13-49-41.RSNTL",package="sentinelreadr") xml <- read_rsntl(input_filename,chkDMV=T)
Get test details file 3
patient <- lapply(xml$test_details,testdetails_xml_to_table) DT::datatable(patient[[1]])
Get data details 3
data <- lapply(xml$clinical_data,clinical_xml_to_table) DT::datatable(data[[1]])
Check that files that are corrupt complete but return a NULL xml
input_filename <- system.file("extdata","2014_B_07-01-2021_error_1.RSNTL",package="sentinelreadr") xml <- read_rsntl(input_filename,chkDMV=T) is.null(xml)
input_filename <- system.file("extdata","2014_B_07-01-2021_error_2.RSNTL",package="sentinelreadr") xml <- read_rsntl(input_filename,chkDMV=T) is.null(xml)
Use the process_files function to process all .RSNTL files in a directory to create a table of patient details and a table with all the reading from all the files with a column that links them to the patient id
# The directory of RSNTL files directory <- system.file("extdata",package="sentinelreadr") # A file to hold the patient table patienttable <- file.path(Sys.getenv("HOME"),"patient.csv") # A file to hold the reading table resultstable <- file.path(Sys.getenv("HOME"),"results.csv") # A file to hold the reading table results <- process_files(directory, pattablefile=patienttable, restablefile=resultstable, silent=F,db=F) lapply(results,nrow) logr::log_close()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.