Commits (51)
......@@ -6,3 +6,9 @@
^.*\.Rproj$
^\.Rproj\.user$
^\.spelling$
^\.ccache$
^\.github$
^tic\.R$
^CRAN-RELEASE$
^cran-comments\.md$
^logfile\.log$
on:
push:
pull_request:
# for now, CRON jobs only run on the default branch of the repo (i.e. usually on master)
schedule:
# * is a special character in YAML so you have to quote this string
- cron: "0 4 * * *"
name: test-coverage
jobs:
all:
runs-on: ${{ matrix.config.os }}
name: ${{ matrix.config.os }} (${{ matrix.config.r }})
strategy:
fail-fast: false
matrix:
config:
# use a different tic template type if you do not want to build on all listed platforms
#- { os: windows-latest, r: "release", java: "true" }
#- { os: macOS-latest, r: "release", java: "true" }
- { os: ubuntu-latest, r: "release", java: "true" }
env:
# otherwise remotes::fun() errors cause the build to fail. Example: Unavailability of binaries
R_REMOTES_NO_ERRORS_FROM_WARNINGS: true
CRAN: ${{ matrix.config.cran }}
# we are not allowed to write to ~/.ccache on GH Actions
# setting some ccache options
CCACHE_BASEDIR: ${{ GITHUB.WORKSPACE }}
CCACHE_DIR: ${{ GITHUB.WORKSPACE }}/.ccache
CCACHE_NOHASHDIR: true
CCACHE_SLOPPINESS: include_file_ctime
# prevent rgl issues because no X11 display is available
RGL_USE_NULL: true
# if you use bookdown or blogdown, replace "PKGDOWN" by the respective
# capitalized term. This also might need to be done in tic.R
BUILD_PKGDOWN: ${{ matrix.config.pkgdown }}
# macOS >= 10.15.4 linking
SDKROOT: /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk
# use GITHUB_TOKEN from GitHub to workaround rate limits in {remotes}
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@main
- uses: r-lib/actions/setup-r@master
with:
r-version: ${{ matrix.config.r }}
Ncpus: 4
# LaTeX. Installation time:
# Linux: ~ 1 min
# macOS: ~ 1 min 30s
# Windows: never finishes
- uses: r-lib/actions/setup-tinytex@master
if: matrix.config.latex == 'true'
- uses: r-lib/actions/setup-pandoc@master
if: matrix.config.latex == 'true'
- uses: actions/setup-java@main
if: matrix.config.java == 'true'
with:
java-version: '8'
# set date/week for use in cache creation
# https://github.community/t5/GitHub-Actions/How-to-set-and-access-a-Workflow-variable/m-p/42970
# - cache R packages daily
- name: "[Cache] Prepare daily timestamp for cache"
if: runner.os != 'Windows'
id: date
run: echo "::set-output name=date::$(date '+%d-%m')"
- name: "[Cache] Cache R packages"
if: runner.os != 'Windows'
uses: pat-s/always-upload-cache@master
with:
path: ${{ env.R_LIBS_USER }}
key: ${{ runner.os }}-r-${{ matrix.config.r }}-${{steps.date.outputs.date}}
restore-keys: ${{ runner.os }}-r-${{ matrix.config.r }}-${{steps.date.outputs.date}}
# for some strange Windows reason this step and the next one need to be decoupled
- name: "[Stage] Prepare"
run: |
Rscript -e "if (!requireNamespace('remotes')) install.packages('remotes', type = 'source')"
Rscript -e "if (getRversion() < '3.2' && !requireNamespace('curl')) install.packages('curl', type = 'source')"
- name: "[Stage] [Linux] Install curl"
if: runner.os == 'Linux'
run: sudo apt install libcurl4-openssl-dev
- name: "[Stage] Configure R Java"
if: runner.os != 'Windows' && matrix.config.java == 'true'
run: sudo R CMD javareconf
- name: Install dependencies
run: |
install.packages(c("remotes"))
remotes::install_deps(dependencies = TRUE)
remotes::install_cran("covr")
shell: Rscript {0}
- name: Test coverage
run: covr::codecov()
shell: Rscript {0}
on:
push:
pull_request:
# for now, CRON jobs only run on the default branch of the repo (i.e. usually on master)
schedule:
# * is a special character in YAML so you have to quote this string
- cron: "0 4 * * *"
name: lint
jobs:
all:
runs-on: ${{ matrix.config.os }}
name: ${{ matrix.config.os }} (${{ matrix.config.r }})
strategy:
fail-fast: false
matrix:
config:
# use a different tic template type if you do not want to build on all listed platforms
#- { os: windows-latest, r: "release", java: "true" }
#- { os: macOS-latest, r: "release", java: "true" }
- { os: ubuntu-latest, r: "release", java: "true" }
env:
# otherwise remotes::fun() errors cause the build to fail. Example: Unavailability of binaries
R_REMOTES_NO_ERRORS_FROM_WARNINGS: true
CRAN: ${{ matrix.config.cran }}
# we are not allowed to write to ~/.ccache on GH Actions
# setting some ccache options
CCACHE_BASEDIR: ${{ GITHUB.WORKSPACE }}
CCACHE_DIR: ${{ GITHUB.WORKSPACE }}/.ccache
CCACHE_NOHASHDIR: true
CCACHE_SLOPPINESS: include_file_ctime
# prevent rgl issues because no X11 display is available
RGL_USE_NULL: true
# if you use bookdown or blogdown, replace "PKGDOWN" by the respective
# capitalized term. This also might need to be done in tic.R
BUILD_PKGDOWN: ${{ matrix.config.pkgdown }}
# macOS >= 10.15.4 linking
SDKROOT: /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk
# use GITHUB_TOKEN from GitHub to workaround rate limits in {remotes}
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@main
- uses: r-lib/actions/setup-r@master
with:
r-version: ${{ matrix.config.r }}
Ncpus: 4
# LaTeX. Installation time:
# Linux: ~ 1 min
# macOS: ~ 1 min 30s
# Windows: never finishes
- uses: r-lib/actions/setup-tinytex@master
if: matrix.config.latex == 'true'
- uses: r-lib/actions/setup-pandoc@master
if: matrix.config.latex == 'true'
- uses: actions/setup-java@main
if: matrix.config.java == 'true'
with:
java-version: '8'
# set date/week for use in cache creation
# https://github.community/t5/GitHub-Actions/How-to-set-and-access-a-Workflow-variable/m-p/42970
# - cache R packages daily
- name: "[Cache] Prepare daily timestamp for cache"
if: runner.os != 'Windows'
id: date
run: echo "::set-output name=date::$(date '+%d-%m')"
- name: "[Cache] Cache R packages"
if: runner.os != 'Windows'
uses: pat-s/always-upload-cache@master
with:
path: ${{ env.R_LIBS_USER }}
key: ${{ runner.os }}-r-${{ matrix.config.r }}-${{steps.date.outputs.date}}
restore-keys: ${{ runner.os }}-r-${{ matrix.config.r }}-${{steps.date.outputs.date}}
# for some strange Windows reason this step and the next one need to be decoupled
- name: "[Stage] Prepare"
run: |
Rscript -e "if (!requireNamespace('remotes')) install.packages('remotes', type = 'source')"
Rscript -e "if (getRversion() < '3.2' && !requireNamespace('curl')) install.packages('curl', type = 'source')"
- name: "[Stage] [Linux] Install curl"
if: runner.os == 'Linux'
run: sudo apt install libcurl4-openssl-dev
- name: "[Stage] Configure R Java"
if: runner.os != 'Windows' && matrix.config.java == 'true'
run: sudo R CMD javareconf
- name: Install dependencies
run: |
install.packages(c("remotes"))
remotes::install_deps(dependencies = TRUE)
remotes::install_cran("lintr")
shell: Rscript {0}
- name: Lint
run: lintr::lint_package()
shell: Rscript {0}
## tic GitHub Actions template: linux-macos-windows-deploy
## revision date: 2020-05-21
on:
push:
pull_request:
# for now, CRON jobs only run on the default branch of the repo (i.e. usually on master)
schedule:
# * is a special character in YAML so you have to quote this string
- cron: "0 4 * * *"
name: R CMD Check via {tic}
jobs:
all:
runs-on: ${{ matrix.config.os }}
name: ${{ matrix.config.os }} (${{ matrix.config.r }})
strategy:
fail-fast: false
matrix:
config:
# use a different tic template type if you do not want to build on all listed platforms
- { os: windows-latest, r: "release", pkgdown: "true", latex: "true", java: "true" }
- { os: macOS-latest, r: "release", pkgdown: "true", latex: "true", java: "true" }
- { os: ubuntu-latest, r: "release", pkgdown: "true", latex: "true", java: "true" }
env:
# otherwise remotes::fun() errors cause the build to fail. Example: Unavailability of binaries
R_REMOTES_NO_ERRORS_FROM_WARNINGS: true
CRAN: ${{ matrix.config.cran }}
# we are not allowed to write to ~/.ccache on GH Actions
# setting some ccache options
CCACHE_BASEDIR: ${{ GITHUB.WORKSPACE }}
CCACHE_DIR: ${{ GITHUB.WORKSPACE }}/.ccache
CCACHE_NOHASHDIR: true
CCACHE_SLOPPINESS: include_file_ctime
# prevent rgl issues because no X11 display is available
RGL_USE_NULL: true
# if you use bookdown or blogdown, replace "PKGDOWN" by the respective
# capitalized term. This also might need to be done in tic.R
BUILD_PKGDOWN: ${{ matrix.config.pkgdown }}
# macOS >= 10.15.4 linking
SDKROOT: /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk
# use GITHUB_TOKEN from GitHub to workaround rate limits in {remotes}
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@main
- uses: r-lib/actions/setup-r@master
with:
r-version: ${{ matrix.config.r }}
Ncpus: 4
# LaTeX. Installation time:
# Linux: ~ 1 min
# macOS: ~ 1 min 30s
# Windows: never finishes
- uses: r-lib/actions/setup-tinytex@master
if: matrix.config.latex == 'true'
- uses: r-lib/actions/setup-pandoc@master
if: matrix.config.latex == 'true'
- uses: actions/setup-java@main
if: matrix.config.java == 'true'
with:
java-version: '8'
# set date/week for use in cache creation
# https://github.community/t5/GitHub-Actions/How-to-set-and-access-a-Workflow-variable/m-p/42970
# - cache R packages daily
- name: "[Cache] Prepare daily timestamp for cache"
if: runner.os != 'Windows'
id: date
run: echo "::set-output name=date::$(date '+%d-%m')"
- name: "[Cache] Cache R packages"
if: runner.os != 'Windows'
uses: pat-s/always-upload-cache@master
with:
path: ${{ env.R_LIBS_USER }}
key: ${{ runner.os }}-r-${{ matrix.config.r }}-${{steps.date.outputs.date}}
restore-keys: ${{ runner.os }}-r-${{ matrix.config.r }}-${{steps.date.outputs.date}}
# for some strange Windows reason this step and the next one need to be decoupled
- name: "[Stage] Prepare"
run: |
Rscript -e "if (!requireNamespace('remotes')) install.packages('remotes', type = 'source')"
Rscript -e "if (getRversion() < '3.2' && !requireNamespace('curl')) install.packages('curl', type = 'source')"
- name: "[Stage] [Linux] Install curl"
if: runner.os == 'Linux'
run: sudo apt install libcurl4-openssl-dev
- name: "[Stage] Configure R Java"
if: runner.os != 'Windows' && matrix.config.java == 'true'
run: sudo R CMD javareconf
- name: "[Stage] Install"
if: matrix.config.os != 'macOS-latest' || matrix.config.r != 'devel'
run: Rscript -e "remotes::install_github('ropensci/tic')" -e "print(tic::dsl_load())" -e "tic::prepare_all_stages()" -e "tic::before_install()" -e "tic::install()"
- name: "[Stage] Script"
run: Rscript -e 'tic::script()'
- name: "[Stage] After Success"
if: matrix.config.os == 'macOS-latest' && matrix.config.r == 'release'
run: Rscript -e "tic::after_success()"
- name: "[Stage] Upload R CMD check artifacts"
if: failure()
uses: actions/upload-artifact@main
with:
name: ${{ runner.os }}-r${{ matrix.config.r }}-results
path: check
......@@ -24,3 +24,8 @@
/.vscode
!/.lintr
inst/doc
!/.github/
!/tic.R
docs/
!/NEWS.md
!/cran-comments.md
......@@ -8,7 +8,7 @@ variables:
default:
image: ${CI_IMAGE_NAME}:${CI_IMAGE_TAG}
before_script:
- echo "options('repos' = 'https://ftp.fau.de/cran/')" >> /usr/local/lib/R/etc/Rprofile.site
- echo "options('repos' = 'https://cloud.r-project.org/')" >> /usr/local/lib/R/etc/Rprofile.site
- mkdir -p ci
stages:
......@@ -29,7 +29,7 @@ check:
allow_failure: true # necessary when having development-packages (in remotes-section of DESCRIPTION)
script:
- R -e "devtools::install_dev_deps(pkg = '.', upgrade = 'always')"
- R -e "devtools::check(pkg = '.', args = c('--no-tests, --no-vignettes'), build_args = c('--no-build-vignettes'), check_dir = '${CI_PROJECT_DIR}/ci')"
- R -e "rcmdcheck::rcmdcheck(path = '.', args = c('--no-tests', '--no-vignettes', '--as-cran'), build_args = c('--no-build-vignettes'), check_dir = '${CI_PROJECT_DIR}/ci')"
artifacts:
paths:
- "${CI_PROJECT_DIR}/ci/*.Rcheck"
......
Package: DIZutils
Title: Utilities for 'DIZ' R Package Development
Version: 0.0.4
Date: 2020-05-27
Version: 0.0.6
Date: 2020-11-17
Authors@R:
c(person(given = "Jonathan M.",
family = "Mang",
......@@ -13,35 +13,33 @@ Authors@R:
role = "aut",
comment = c(ORCID = "0000-0003-1866-860X")),
person(given = "MIRACUM - Medical Informatics in Research and Care in University Medicine",
role = "fnd"))
Description: Utility functions used for R package development
infrastructure inside the data integration centers ('DIZ') to
standardize and facilitate repetitive tasks such as setting up a
role = "fnd"),
person(given = "Universitätsklinikum Erlangen",
role = "cph"))
Description: 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.
License: GPL-3
URL: https://gitlab.miracum.org/miracum/dqa/dizutils
BugReports:
https://gitlab.miracum.org/miracum/dqa/dizutils/issues
URL: https://github.com/miracum/misc-dizutils
BugReports: https://github.com/miracum/misc-dizutils/issues
Depends:
R (>= 2.10)
R (>= 3.1.0)
Imports:
config,
data.table,
DBI,
DBI (>= 1.1.0),
RJDBC,
RPostgres,
shiny,
shinyjs
Suggests:
knitr,
lintr,
qpdf,
rmarkdown,
testthat
biocViews:
Copyright: Universitätsklinikum Erlangen
Encoding: UTF-8
Language: en-US
LazyData: true
RoxygenNote: 7.1.0
SystemRequirements: libpq >= 9.0: libpq-dev (deb) or
postgresql-devel (rpm)
RoxygenNote: 7.1.1
# [](https://gitlab.miracum.org/miracum/misc/dizutils/compare/v0.0.4...v) (2020-11-13)
### fix
* fixed oracle and postrges connection setup ([e45c420](https://gitlab.miracum.org/miracum/misc/dizutils/commit/e45c420c06825f41511b44c5b824a896211ee8ce))
### refactor
* added system requirements for cran checks ([52d9eee](https://gitlab.miracum.org/miracum/misc/dizutils/commit/52d9eee3b17a64cbc790480e8db6fbe9e5bc0ffd))
## [0.0.4](https://gitlab.miracum.org/miracum/misc/dizutils/compare/v0.0.3...v0.0.4) (2020-06-04)
## [0.0.3](https://gitlab.miracum.org/miracum/misc/dizutils/compare/v0.0.2...v0.0.3) (2020-05-07)
## 0.0.2 (2020-04-20)
......@@ -5,18 +5,14 @@
#' @param pathname A character string. A path name to be cleaned
#' (to have a tailing slash).
#' @return The result is the input but with an tailing slash.
#' @examples
#' clean_path_name("./path/to/file/structure")
#' > "./path/to/file/structure/"
#'
#' @export
#'
#' @examples
#' \dontrun{
#' # Both function calls will return "home/test/"
#' clean_path_name("home/test")
#' clean_path_name("home/test/")
#' }
#'
#' @export
#'
clean_path_name <- function(pathname) {
return(gsub("([[:alnum:]])$", "\\1/", pathname))
......
......@@ -5,8 +5,11 @@
#' @inheritParams feedback
#' @return No return value, called for side effects (see description)
#' @examples
#' close_all_connections("path/to/logfile/dir/")
#'
#' \donttest{
#' close_all_connections(
#' logfile_dir = tempdir(),
#' headless = TRUE
#' )}
#' @export
#'
close_all_connections <- function(logfile_dir, headless) {
......@@ -16,7 +19,7 @@ close_all_connections <- function(logfile_dir, headless) {
logfile_dir = logfile_dir,
headless = headless
)
lapply(showConnections(), close)
closeAllConnections()
feedback(
"Closed all file-connections.",
findme = "0c5cb72ecc",
......
......@@ -24,15 +24,17 @@
#' @return If successful, the result will be the established connection.
#' Otherwise the result will be null.
#' @examples
#' /dontrun{
#' \dontrun{
#' db_con <- DIZutils::db_connection(
#' db_name = "i2b2",
#' db_type = "postgres",
#' headless = true,
#' logfile_dir = "./path/to/logfile/dir/"
#' headless = TRUE,
#' logfile_dir = tempdir()
#' )}
#'
#' @seealso \code{\link{DBI::dbConnect}}, \code{\link{RPostgres::dbConnect}}
#' @seealso{
#' \code{\link[DBI]{dbConnect}}, \code{\link[RPostgres]{RPostgres}}
#' }
#'
#' @export
#'
......@@ -45,97 +47,117 @@ db_connection <- function(db_name,
timeout = 30,
logfile_dir = NULL,
lib_path = NULL) {
stopifnot(
is.character(db_name),
is.character(db_type),
is.logical(headless),
is.logical(from_env),
ifelse(is.null(settings), TRUE, is.list(settings)),
is.numeric(timeout),
ifelse(is.null(logfile_dir), TRUE, is.character(logfile_dir)),
ifelse(is.null(lib_path), TRUE, is.character(lib_path))
)
db_con <- NULL
tryCatch({
stopifnot(is.character(db_name),
is.character(db_type),
is.logical(headless),
is.logical(from_env),
ifelse(is.null(settings), TRUE, is.list(settings)),
is.numeric(timeout),
ifelse(is.null(logfile_dir), TRUE, is.character(logfile_dir)),
ifelse(is.null(lib_path), TRUE, is.character(lib_path)))
db_type <- toupper(db_type)
db_name <- toupper(db_name)
db_type <- toupper(db_type)
db_name <- toupper(db_name)
if (isTRUE(from_env)) {
dbname <- Sys.getenv(paste0(db_name, "_DBNAME"))
host <- Sys.getenv(paste0(db_name, "_HOST"))
port <- Sys.getenv(paste0(db_name, "_PORT"))
user <- Sys.getenv(paste0(db_name, "_USER"))
password <- Sys.getenv(paste0(db_name, "_PASSWORD"))
if (isTRUE(from_env)) {
dbname <- Sys.getenv(paste0(db_name, "_DBNAME"))
host <- Sys.getenv(paste0(db_name, "_HOST"))
port <- Sys.getenv(paste0(db_name, "_PORT"))
user <- Sys.getenv(paste0(db_name, "_USER"))
password <- Sys.getenv(paste0(db_name, "_PASSWORD"))
} else if (isFALSE(from_env)) {
stopifnot(
is.list(settings),
length(settings) >= 4
)
} else if (isFALSE(from_env)) {
stopifnot(is.list(settings),
length(settings) >= 4)
dbname <- settings$dbname
host <- settings$host
port <- settings$port
user <- settings$user
password <- settings$password
}
host <- settings$host
port <- settings$port
user <- settings$user
password <- settings$password
}
if (db_type == "ORACLE") {
if (is.null(lib_path)) {
if (isTRUE(from_env)) {
lib_path <- Sys.getenv(paste0(db_name, "_DRIVER"))
} else {
lib_path <- settings$lib_path
}
}
if (db_type == "ORACLE") {
## create driver
drv <- RJDBC::JDBC("oracle.jdbc.OracleDriver",
classPath = lib_path)
stopifnot(lib_path != "" || !is.null(lib_path))
if (isTRUE(from_env)) {
sid <- Sys.getenv(paste0(db_name, "_SID"))
} else if (isFALSE(from_env)) {
sid <- settings$sid
}
## create driver
drv <- RJDBC::JDBC("oracle.jdbc.OracleDriver",
classPath = lib_path)
## create URL
url <- paste0("jdbc:oracle:thin:@//", host, ":", port, "/", sid)
if (isTRUE(from_env)) {
sid <- Sys.getenv(paste0(db_name, "_SID"))
} else if (isFALSE(from_env)) {
sid <- settings$sid
}
## create connection
db_con <- tryCatch({
conn <- DBI::dbConnect(
drv = drv,
url = url,
user = user,
password = password
)
conn
}, error = function(e) {
conn <- NULL
conn
}, finally = function(f) {
return(conn)
})
## create URL
url <- paste0("jdbc:oracle:thin:@//", host, ":", port, "/", sid)
} else if (db_type == "POSTGRES") {
drv <- RPostgres::Postgres()
## create connection
db_con <- tryCatch({
conn <- DBI::dbConnect(
drv = drv,
url = url,
user = user,
password = password
)
conn
}, error = function(e) {
conn <- NULL
conn
}, finally = function(f) {
return(conn)
})
} else if (db_type == "POSTGRES") {
drv <- RPostgres::Postgres()
db_con <- tryCatch({
conn <- RPostgres::dbConnect(
drv = drv,
dbname = dbname,
host = host,
port = port,
user = user,
password = password,
connect_timeout = timeout
db_con <- tryCatch({
conn <- RPostgres::dbConnect(
drv = drv,
dbname = dbname,
host = host,
port = port,
user = user,
password = password,
connect_timeout = timeout
)
conn
}, error = function(e) {
conn <- NULL
conn
}, finally = function(f) {
return(conn)
})
}
if (is.null(db_con)) {
feedback(
"DB connection error",
findme = "9431c8c61f",
logfile_dir = logfile_dir,
headless = headless,
type = "Error"
)
conn
}, error = function(e) {
conn <- NULL
conn
}, finally = function(f) {
return(conn)
})
}
if (is.null(db_con)) {
}
},
error = function(cond) {
feedback(
"DB connection error",
findme = "9431c8c61f",
print_this = paste0("Error while trying to establish a db-connection: ",
cond),
type = "Error",
logfile_dir = logfile_dir,
headless = headless
headless = headless,
findme = "c16b60a6ff"
)
}
return(NULL)
})
return(db_con)
}
......@@ -45,10 +45,9 @@
#' print_this = "Error occured when counting source_data",
#' type = "Error",
#' findme = "255bb3695c",
#' logfile_dir = rv$logfile_dir,
#' headless = rv$headless
#' logfile_dir = tempdir(),
#' headless = TRUE
#' )
#'
#' @export
#'
......@@ -69,7 +68,7 @@ feedback <-
# If the gui is active, show the message to the user.
# If its an error message, also show the error messages in the gui
# even if the user did not explicitely said it should be displayed
# even if the user did not explicitly said it should be displayed
# in the gui
if (isTRUE(ui) ||
(isFALSE(headless) &&
......@@ -272,6 +271,7 @@ feedback_to_logfile <-
# and a linebreak at the end:
res <- paste0("[", Sys.time(), "] ", res, "\n")
logfile_dir <- repair_dir(logfile_dir)
path_with_file <- paste0(logfile_dir, "logfile.log")
# Open the connection to the logfile:
......@@ -282,6 +282,13 @@ feedback_to_logfile <-
close(log_con)
}
repair_dir <- function(dir) {
if (!grepl("\\/$", dir)) {
dir <- paste0(dir, "/")
}
return(dir)
}
#' @title Format the feedback string
#' @description Helper function for the feedback function to combine the input
#' parameters in proper manner to ge a pretty and informative string which
......@@ -323,6 +330,7 @@ feedback_get_formatted_string <-
#' @export
#'
cleanup_old_logfile <- function(logfile_dir) {
logfile_dir <- repair_dir(logfile_dir)
path_with_file <- paste0(logfile_dir, "logfile.log")
# Check if logfile.log is already the logfile for this session:
if (isTRUE(file.exists(path_with_file))) {
......
......@@ -4,7 +4,7 @@
#' @param x A character string. E.g. "hello world" will become "Hello world".
#' @return Returns the input string but with a capital first letter.
#' @examples
#' firstup("first letter will be upper case as return")
#' firstup("first letter of this string will be upper case as return")
#'
#' @export
#'
......
......@@ -11,12 +11,14 @@
#' @inheritParams feedback
#' @return If successful it returns the config, Null otherwise.
#' @examples
#' \donttest{
#' utils_path <- tempdir()
#' config <- get_config(
#' config_file = paste0(utils_path, "/MISC/email.yml"),
#' config_key = "email",
#' logfile_dir = rv$logfile_dir,
#' headless = rv$headless
#' )
#' logfile_dir = tempdir(),
#' headless = TRUE
#' )}
#'
#' @export
#'
......
......@@ -9,11 +9,12 @@
#' @inheritParams db_connection
#' @return If successful it returns the config, null otherwise.
#' @examples
#' \donttest{
#' get_config_env(
#' system_name = "i2b2",
#' logfile_dir = "/path/to/logfile/",
#' logfile_dir = tempdir(),
#' headless = FALSE
#' )
#' )}
#'
#' @export
#'
......
......@@ -8,6 +8,7 @@
#' @seealso \url{http://adv-r.had.co.nz/Environments.html}
#' @return No return value, called for side effects (see description).
#' @examples
#' utils_path <- tempdir()
#' global_env_hack(
#' key = "utils_path",
#' val = utils_path,
......
......@@ -7,10 +7,16 @@
#' @param sql_statement A character string containing a valid SQL statement.
#' @return Returns the result of the db-query.
#' @examples
#' \dontrun{
#' db_con <- DIZutils::db_connection(
#' db_name = "i2b2",
#' db_type = "postgres"
#' )
#'
#' query_database(
#' db_con = db_con,
#' sql_statement = "SELECT * FROM table_name;"
#' )
#' )}
#'
#' @export
#'
......
......@@ -4,12 +4,12 @@
#' necessary for the database connections with \code{db_connection}.
#'
#' @param env_file A character. The full path including the file name to
#' the file containing the environment variable defintions to be loaded.
#' the file containing the environment variable definitions to be loaded.
#'
#' @seealso \code{Sys.setenv}
#' @return No return value, called for side effects (see description)
#' @examples
#' set_env_vars("./.env")
#' \dontrun{set_env_vars("./.env")}
#'
#' @export
#'
......
# DIZutils (!!!under development!!!)
# DIZutils
<!-- badges: start -->
[![pipeline status](https://gitlab.miracum.org/miracum/dqa/dizutils/badges/master/pipeline.svg)](https://gitlab.miracum.org/miracum/dqa/dizutils/commits/master)
[![coverage report](https://gitlab.miracum.org/miracum/dqa/dizutils/badges/master/coverage.svg)](https://gitlab.miracum.org/miracum/dqa/dizutils/commits/master)
[![R CMD Check via {tic}](https://github.com/miracum/misc-dizutils/workflows/R%20CMD%20Check%20via%20{tic}/badge.svg?branch=master)](https://github.com/miracum/misc-dizutils/actions)
[![linting](https://github.com/miracum/misc-dizutils/workflows/lint/badge.svg?branch=master)](https://github.com/miracum/misc-dizutils/actions)
[![test-coverage](https://github.com/miracum/misc-dizutils/workflows/test-coverage/badge.svg?branch=master)](https://github.com/miracum/misc-dizutils/actions)
[![codecov](https://codecov.io/gh/miracum/misc-dizutils/branch/master/graph/badge.svg)](https://codecov.io/gh/miracum/misc-dizutils)
[![pipeline status](https://gitlab.miracum.org/miracum/misc/dizutils/badges/master/pipeline.svg)](https://gitlab.miracum.org/miracum/misc/dizutils/commits/master)
[![coverage report](https://gitlab.miracum.org/miracum/misc/dizutils/badges/master/coverage.svg)](https://gitlab.miracum.org/miracum/misc/dizutils/commits/master)
[![CRAN Status Badge](https://www.r-pkg.org/badges/version-ago/DIZutils)](https://cran.r-project.org/package=DIZutils)
[![Cran Checks](https://cranchecks.info/badges/worst/DIZutils)](https://cran.r-project.org/web/checks/check_results_DIZutils.html)
<!-- badges: end -->
The R package `DIZutils` provides utility functions used for 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.
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:
```r
install.packages("DIZutils")
```
The development version can be installed using
```r
install.packages("devtools")
devtools::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 neccessary connection settings from the active environment (see below how to use the function `set_env_vars` to set environment variables).
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 (via the R package [`RPostgres`](https://cran.r-project.org/web/packages/RPostgres/index.html))
* oracle (via the R packages [`RJDBC::JDBC`](https://cran.r-project.org/web/packages/RJDBC/) and [`DBI`](https://cran.r-project.org/web/packages/DBI/))
* postgres (via the R package [`RPostgres`](https://CRAN.R-project.org/package=RPostgres))
* oracle (via the R packages [`RJDBC`](https://CRAN.R-project.org/package=RJDBC) and [`DBI`](https://CRAN.R-project.org/package=DBI/))
### postgres
The following environment variables need to be set to the active environment in order to connect with a postgres database:
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:
| Variable | Description |
| ----------------- | ------------------------------------------------------------------------- |
......@@ -29,7 +50,7 @@ The following environment variables need to be set to the active environment in
| I2B2_USER | The name of the 'I2B2_USER'. |
| I2B2_PASSWORD | The 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 enviroment variables and thus must match with the environment variables' prefix.
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.
```r
db_con <- DIZutils::db_connection(
......@@ -46,11 +67,13 @@ The following environment variables need to be set to the active environment in
| ----------------- | ------------------------------------------------------------------------- |
| MYORACLEDB_HOST | The hostname/ IP address of your oracle instance. |
| MYORACLEDB_DBNAME | The name of the oracle-database. |
| MYORACLEDB_DRIVER | The path to the oracle jdbc driver. |
| MYORACLEDB_SID | The SID of the oracle-database. |
| MYORACLEDB_PORT | The port, your oracle postgres instance is running on. |
| MYORACLEDB_USER | The name of the 'MYORACLEDB_USER'. |
| MYORACLEDB_PASSWORD | The 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 enviroment 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.
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.
```r
db_con <- DIZutils::db_connection(
......@@ -68,9 +91,9 @@ In order to set up a database connection using the function `DIZutils::db_connec
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](https://docs.docker.com/compose/env-file/) (currently, neither empty lines nor the using of comments ('#') is being supporte by `DIZutils::set_env_vars`).
The design of the `envfile` is based on the [`.env` file for defining environment variables when using docker-compose commands](https://docs.docker.com/compose/env-file/) (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 examplary 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`.
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
......
## R CMD check results
There were no ERRORs or WARNINGs.