Learn R Programming

⚠️There's a newer version (0.1.3) of this package.Take me there.

DIZutils

The R package DIZutils provides utility functions used for the R package development infrastructure inside the data integration centers ('DIZ') to standardize and facilitate repetitive tasks such as setting up a database connection or issuing notification messages and to avoid redundancy.

Installation

You can install DIZutils directly from CRAN:

install.packages("DIZutils")

The development version can be installed using

install.packages("remotes")
remotes::install_github("miracum/misc-dizutils", ref = "development")

Basic functions

db_connection

The function DIZutils::db_connection provides one simple interface for connecting to various types of databases. It reads necessary connection settings from the active environment (see below how to use the function set_env_vars to set environment variables).

The following database types are currently supported:

postgres

The following environment variables need to be set to the active environment in order to connect with a postgres database with "i2b2" as name of the database to connect with:

VariableDescription
I2B2_HOSTThe hostname/ IP address of your pg instance.
I2B2_DBNAMEThe name of the pg-database.
I2B2_PORTThe port, your pg postgres instance is running on.
I2B2_USERThe name of the 'I2B2_USER'.
I2B2_PASSWORDThe password of the 'I2B2_USER' of your pg instance.

To establish the connection, please set those environment variables accordingly and execute the following command. The argument db_name is used to detect the corresponding environment variables and thus must match with the environment variables' prefix.

db_con <- DIZutils::db_connection(
    system_name = "i2b2",
    db_type = "postgres"
  )

oracle

The following environment variables need to be set to the active environment in order to connect with an oracle database:

VariableDescription
MYORACLEDB_HOSTThe hostname/ IP address of your oracle instance.
MYORACLEDB_DBNAMEThe name of the oracle-database.
MYORACLEDB_DRIVERThe path to the oracle jdbc driver.
MYORACLEDB_SIDThe SID of the oracle-database.
MYORACLEDB_PORTThe port, your oracle postgres instance is running on.
MYORACLEDB_USERThe name of the 'MYORACLEDB_USER'.
MYORACLEDB_PASSWORDThe password of the 'MYORACLEDB_USER' of your oracle instance.

To establish the connection, please set those environment variables accordingly and execute the following command. The argument db_name is used to detect the corresponding environment variables and thus must match with the environment variables' prefix. Furthermore, an ojdbc*.jar-file needs to be provided via the function's lib_path argument.

db_con <- DIZutils::db_connection(
  system_name = "myoracledb",
  db_type = "oracle",
  lib_path = "path/to/ojdbc*.jar"
)

set_env_vars

In order to set up a database connection using the function DIZutils::db_connection, one needs to provide the required connection settings via environment variables. To facilitate the process of making such environment variables available within the current R session, the function DIZutils::set_env_vars works as a wrapper function around the base R method Sys.setenv. It takes the file name of a text file with the definitions of the environment variables as input, and sets those environment variables within the current R session.

DIZutils::set_env_vars("path/to/envfile")

The design of the envfile is based on the .env file for defining environment variables when using docker-compose commands. See here (currently, neither empty lines nor the using of comments ('#') is being supported by DIZutils::set_env_vars).

To create an envfile for connecting with an i2b2 database, the following exemplary definitions of environment variables should be written to a simple textfile, e.g. named envfile, which can then be passed as argument to DIZutils::set_env_vars.

I2B2_HOST=123.45.56.8
I2B2_PORT=5432
I2B2_DBNAME=i2b2
I2B2_USER=user
I2B2_PASSWORD=password

More Infos

Copy Link

Version

Install

install.packages('DIZutils')

Monthly Downloads

644

Version

0.0.13

License

GPL-3

Issues

Pull Requests

Stars

Forks

Maintainer

Jonathan M. Mang

Last Published

February 11th, 2022

Functions in DIZutils (0.0.13)

cleanup_old_logfile

Archives the current logfile and creates a new blank one.
get_config

get_config helper function
format_posixct

Formats a given POSIXct timestamp without the need of manually specifing format parameters.
clear

Clean the console and environment-variables
set_env_vars

set_env_vars helper function
dot_helper

Dot Helper
query_database

query_database helper function
global_env_hack

global_env_hack
close_connection

close_connection helper function
combine_stats

Combine aggregated statistics.
%notin%

notin helper function
get_config_env

get_config_env helper function
xml_2_json

Quickly transform a xml objet into a json object.
setdiff_all

Get the difference of two vectors in both directions.
is_date_format

Checks if a string matches a given date format.
setenv2

Assign variables to the system environment.
clean_path_name

clean_path_name helper function
equals2

Compare two elements and return true if both elements are the same.
check_if_table_exists

Check if a database table exists.
db_connection

db_connection helper function
feedback

Function to feedback messages either to the user and/or to the console and to the logfile.
get_db_systems

Quickly get all currently implemented database systems
firstup

Converts the first letter of the input string to uppercase