Code Monkey home page Code Monkey logo

readepi's Introduction

readepi

readepi provides functions for importing data into R from files and common health information systems.

License: MIT R-CMD-check Codecov test coverage lifecycle-concept

Installation

You can install the development version of readepi from GitHub with:

# install.packages("devtools")
# devtools::install_github("epiverse-trace/readepi@develop", build_vignettes = TRUE)
library(readepi)

Importing data in R

The readepi() function allows importing data from several file types and database management systems. These include:

  • all file formats in the rio package.
  • file formats that are not accounted for by rio
  • relational database management systems (RDBMS) such as REDCap, MS SQL server, DHIS2
  • Fingertips (repository of public health indicators in England)

The function returns an object of class list with one or more data frames.

Importing data from files

# READING DATA FROM JSON file
file <- system.file("extdata", "test.json", package = "readepi")
data <- readepi(file_path = file)

# IMPORTING DATA FROM THE SECOND EXCEL SHEET
file <- system.file("extdata", "test.xlsx", package = "readepi")
data <- readepi(file_path = file, which = "Sheet2")

# IMPORTING DATA FROM THE FIRST AND SECOND EXCEL SHEETS
file <- system.file("extdata", "test.xlsx", package = "readepi")
data <- readepi(file_path = file, which = c("Sheet2", "Sheet1"))

Importing data from several files in a directory

# READING ALL FILES IN A GIVEN DIRECTORY
dir_path <- system.file("extdata", package = "readepi")
data <- readepi(file_path = dir_path)

# READING ONLY '.txt' FILES
data <- readepi(file_path = dir_path, pattern = ".txt")

# READING '.txt' and '.xlsx' FILES
data <- readepi(file_path = dir_path, pattern = c(".txt", ".xlsx"))

Importing data from DBMS

To read data from DBMS, users can either provide the details of the tables of interest or an SQL query (see vignette for illustration). The current version of readepi allows for data import from:

  1. MS SQL server,
  2. MySQL server,
  3. PostgreSQL server.

This requires the users to:

  1. install the MS SQL driver that is compatible with your SQL server version. Details about this installation process can be found in the vignette.
  2. create a credentials file where the user credential details will be stored. Use the show_example_file() to see a template of this file.

Note that the examples in this section are based on a MySQL server that does not require the user to specify the driver name. But it is important to keep in mind that specify the driver name is a requirement for MS SQL server.

# DISPLAY THE STRUCTURE OF THE CREDENTIALS FILE
show_example_file()

# DEFINING THE CREDENTIALS FILE
credentials_file <- system.file("extdata", "test.ini", package = "readepi")

# READING ALL FIELDS AND RECORDS FROM A REDCap PROJECT
data <- readepi(
  credentials_file = credentials_file,
  project_id = "SD_DATA"
)
project_data <- data$data
project_metadeta <- data$metadata

# DISPLAY THE LIST OF ALL TABLES IN A DATABASE HOSTED IN A MySQL SERVER
# for the test MySQL server, the driver name does not need to be specified
show_tables(
  credentials_file = credentials_file,
  project_id = "Rfam",
  driver_name = ""
)

# VISUALIZE THE FIRST 5 ROWS OF THE TABLE 'author'
visualise_table(
  credentials_file = credentials_file,
  source = "author", # this is the table name
  project_id = "Rfam", # this is the database name
  driver_name = ""
)

# READING ALL FIELDS AND ALL RECORDS FROM A DATABASE HOSTED BY A MS SQL SERVER
data <- readepi(
  credentials_file = credentials_file,
  project_id = "Rfam", # this is the database name
  driver_name = "",
  source = "author"
)

# READING DATA FROM DHIS2
data <- readepi(
  credentials_file = credentials_file,
  project_id = "DHIS2_DEMO",
  dataset = "pBOMPrpg1QX",
  organisation_unit = "DiszpKrYNg8",
  data_element_group = NULL,
  start_date = "2014",
  end_date = "2023"
)

# READING FROM FINFERTIPS
data <- readepi(
  indicator_id = 90362,
  area_type_id = 202,
  parent_area_type_id = 6 # optional
)

Vignette

The vignette of the readepi contains detailed illustrations about the use of each function. This can be accessed by typing the command below:

# OPEN THE VIGNETTE WITHIN RSTUDIO
vignette("readepi")

# OPEN THE VIGNETTE IN YOUR WEB BROWSER. 
browseVignettes("readepi")

Development

Contributions

Contributions are welcome via pull requests.

Code of Conduct

Please note that the readepi project is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms.

readepi's People

Contributors

karim-mane avatar thibautjombart avatar actions-user avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.