From e240b1d79a6b3d30f32fc5889aef44dd82b47054 Mon Sep 17 00:00:00 2001 From: hsonne Date: Fri, 19 Jun 2020 11:48:50 +0200 Subject: [PATCH 01/14] Back to dev version --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 0ccbca4..72ff235 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,5 +1,5 @@ Package: kwb.db -Version: 0.5.0 +Version: 0.5.0.9000 Title: Functions supporting data base access Description: This package contains some useful functions, especially for simplifying data transfer between MS Access databases and R. With the From 21ef4f90cbeea0d6953c6f3a02121b3cb89a5a6f Mon Sep 17 00:00:00 2001 From: hsonne Date: Fri, 9 Oct 2020 17:05:20 +0200 Subject: [PATCH 02/14] Do not use kwb.db::: --- R/connect.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/connect.R b/R/connect.R index 2ae3f74..905a435 100644 --- a/R/connect.R +++ b/R/connect.R @@ -231,7 +231,7 @@ odbcConnectionExcel <- function(db, use2007Driver = NULL, ...) "This is a", ifelse(is64BitR(), "64", "32"), "Bit R session. " ) - kwb.db:::clean_stop(msg, if (! is64BitR()) { + clean_stop(msg, if (! is64BitR()) { "You may try to run R in 32 Bit mode." } else { "You need to have 64 Bit ODBC drivers installed." From ce904ca94acc402e23391531074c9dbbd46fcd47 Mon Sep 17 00:00:00 2001 From: hsonne Date: Fri, 9 Oct 2020 17:06:18 +0200 Subject: [PATCH 03/14] Fix :bug: (typo "tlbList"), simply use "tables" --- R/hsTables.R | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/R/hsTables.R b/R/hsTables.R index 038e059..1822343 100644 --- a/R/hsTables.R +++ b/R/hsTables.R @@ -67,31 +67,34 @@ hsTables <- function( }) # Try to use the RODBC-function first - tblList <- try(RODBC::sqlTables(con)) + tables <- try(RODBC::sqlTables(con)) - if (inherits(tblList, "try-error")) { + if (inherits(tables, "try-error")) { - error <- as.character(tblList) + error <- as.character(tables) # Try to use the odbc32-function next - tblList <- try(odbc32::sqlTables(con)) + tables <- try(odbc32::sqlTables(con)) - if (inherits(tlbList, "try-error")) { + if (inherits(tables, "try-error")) { clean_stop( "Could not fetch a table list.\n", "RODBC::sqlTables() returned: ", error, "\n", - "odbc32::sqlTables() returned: ", as.character(tblList) + "odbc32::sqlTables() returned: ", as.character(tables) ) } } if (excludeSystemTables) { - tblList <- tblList[tblList$TABLE_TYPE != "SYSTEM TABLE", ] + tables <- tables[tables$TABLE_TYPE != "SYSTEM TABLE", ] } if (namesOnly) { - tblList$TABLE_NAME + + tables$TABLE_NAME + } else { - tblList + + tables } } From 0a28cf43403c1742e46844211d97d89fe05fa55e Mon Sep 17 00:00:00 2001 From: hsonne Date: Fri, 9 Oct 2020 17:07:39 +0200 Subject: [PATCH 04/14] Add getDatabaseFieldInfo() --- DESCRIPTION | 2 +- R/getDatabaseFieldInfo.R | 28 ++++++++++++++++++++++++++++ man/getDatabaseFieldInfo.Rd | 18 ++++++++++++++++++ 3 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 R/getDatabaseFieldInfo.R create mode 100644 man/getDatabaseFieldInfo.Rd diff --git a/DESCRIPTION b/DESCRIPTION index 72ff235..cbf39be 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -40,6 +40,6 @@ Remotes: github::cran/RODBC@1.3-16 Encoding: UTF-8 License: MIT + file LICENSE -RoxygenNote: 7.1.0 +RoxygenNote: 7.1.1 URL: https://github.com/KWB-R/kwb.db BugReports: https://github.com/KWB-R/kwb.db/issues diff --git a/R/getDatabaseFieldInfo.R b/R/getDatabaseFieldInfo.R new file mode 100644 index 0000000..88e8a65 --- /dev/null +++ b/R/getDatabaseFieldInfo.R @@ -0,0 +1,28 @@ +# getDatabaseFieldInfo --------------------------------------------------------- + +#' Get Information on Table Field Names and Types +#' +#' @param db path to MS Access or MS Excel file or name of ODBC data source +#' @return data frame with columns \code{TABLE_NAME}, \code{COLUMN_NAME}, +#' \code{TYPE_NAME}, \code{DECIMAL_DIGITS} +#' @export +#' @importFrom kwb.utils createAccessor moveColumnsToFront removeColumns +#' @importFrom kwb.utils selectColumns +#' +getDatabaseFieldInfo <- function(db) +{ + table_info <- hsTables(db, namesOnly = FALSE) + getcol <- kwb.utils::createAccessor(table_info) + tables <- getcol("TABLE_NAME")[getcol("TABLE_TYPE") == "TABLE"] + + ordinal <- "ORDINAL" + infos <- lapply(stats::setNames(nm = tables), function(tbl) { + info <- hsFields(db, tbl, namesOnly = FALSE) + columns <- c("COLUMN_NAME", "TYPE_NAME", "DECIMAL_DIGITS", ordinal) + info <- kwb.utils::selectColumns(info, columns) + kwb.utils::removeColumns(info[order(info[[ordinal]]), ], ordinal) + }) + + column <- "TABLE_NAME" + kwb.utils::moveColumnsToFront(kwb.utils::rbindAll(infos, column), column) +} diff --git a/man/getDatabaseFieldInfo.Rd b/man/getDatabaseFieldInfo.Rd new file mode 100644 index 0000000..30f3b13 --- /dev/null +++ b/man/getDatabaseFieldInfo.Rd @@ -0,0 +1,18 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/getDatabaseFieldInfo.R +\name{getDatabaseFieldInfo} +\alias{getDatabaseFieldInfo} +\title{Get Information on Table Field Names and Types} +\usage{ +getDatabaseFieldInfo(db) +} +\arguments{ +\item{db}{path to MS Access or MS Excel file or name of ODBC data source} +} +\value{ +data frame with columns \code{TABLE_NAME}, \code{COLUMN_NAME}, + \code{TYPE_NAME}, \code{DECIMAL_DIGITS} +} +\description{ +Get Information on Table Field Names and Types +} From 409547f5d6ae47d17a7e9084813e6b5282ed5774 Mon Sep 17 00:00:00 2001 From: hsonne Date: Fri, 9 Oct 2020 17:13:58 +0200 Subject: [PATCH 05/14] Manually export getDatabaseFieldInfo() --- NAMESPACE | 1 + 1 file changed, 1 insertion(+) diff --git a/NAMESPACE b/NAMESPACE index 6a85a1f..d7cd322 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -6,6 +6,7 @@ export(currentDb) export(dataFrameToSqlTuples) export(dumpDatabase) export(getCurrentSqlDialect) +export(getDatabaseFieldInfo) export(getNamedExcelRanges) export(hsClearTable) export(hsCloseMdb) From 1f324f4e2a407aee83ee198f958e1cca55b27ce8 Mon Sep 17 00:00:00 2001 From: hsonne Date: Mon, 12 Oct 2020 11:45:44 +0200 Subject: [PATCH 06/14] Allow to define names of which to get schema --- NEWS | 5 +++++ R/schema.R | 26 +++++++++++++------------- man/getDatabaseSchema.Rd | 7 ++++++- 3 files changed, 24 insertions(+), 14 deletions(-) diff --git a/NEWS b/NEWS index 89b9866..e640e4e 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,8 @@ +Latest changes +============== + +* getDatabaseSchema(): add arguments "tableNames", "tableTypes" + Changes in kwb.db 0.5.0 (2020-06-19) ==================================== * Try using RODBC functions first before using functions from rodb32 package diff --git a/R/schema.R b/R/schema.R index c5957c7..d7856ef 100644 --- a/R/schema.R +++ b/R/schema.R @@ -30,26 +30,26 @@ printDatabaseSchema <- function(dbSchema) #' Get Database Schema #' #' @param db full path to database (*.mdb, *.xls) or name of ODBC database -#' +#' @param tableNames optional. Vector of table names of tables to be included +#' @param tableTypes types of database objects to be included. Default: +#' \code{c("TABLE", "VIEW")} #' @return list with elements \emph{tables} and \emph{relationships}. Element #' \emph{tables} is a list o named elements with the name representing the #' table names and the elements being lists describing the table... #' -getDatabaseSchema <- function(db) +getDatabaseSchema <- function( + db, tableNames = NULL, tableTypes = c("TABLE", "VIEW") +) { sqlDialect <- ifelse(isMySQL(db), "mysql", "msaccess") - tableInfo <- hsTables(db, namesOnly = FALSE) - - roworder <- order( - tableInfo$TABLE_TYPE, tableInfo$TABLE_NAME - ) - - tableInfo <- tableInfo[roworder, ] - - selected <- tableInfo$TABLE_TYPE %in% c("TABLE", "VIEW") - - tableNames <- sort(tableInfo$TABLE_NAME[selected]) + if (is.null(tableNames)) { + + tableInfo <- hsTables(db, namesOnly = FALSE) + types <- kwb.utils::selectColumns(tableInfo, "TABLE_TYPE") + tableInfo <- tableInfo[types %in% tableTypes, ] + tableNames <- sort(kwb.utils::selectColumns(tableInfo, "TABLE_NAME")) + } databaseSchema <- list(tables = list()) diff --git a/man/getDatabaseSchema.Rd b/man/getDatabaseSchema.Rd index 3dea3a3..bdf4add 100644 --- a/man/getDatabaseSchema.Rd +++ b/man/getDatabaseSchema.Rd @@ -4,10 +4,15 @@ \alias{getDatabaseSchema} \title{Get Database Schema} \usage{ -getDatabaseSchema(db) +getDatabaseSchema(db, tableNames = NULL, tableTypes = c("TABLE", "VIEW")) } \arguments{ \item{db}{full path to database (*.mdb, *.xls) or name of ODBC database} + +\item{tableNames}{optional. Vector of table names of tables to be included} + +\item{tableTypes}{types of database objects to be included. Default: +\code{c("TABLE", "VIEW")}} } \value{ list with elements \emph{tables} and \emph{relationships}. Element From fb2484466cb6377630ace3a8cfc9bf6fc80632b9 Mon Sep 17 00:00:00 2001 From: hsonne Date: Mon, 12 Oct 2020 12:00:06 +0200 Subject: [PATCH 07/14] Consider the types even if names are given --- R/schema.R | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/R/schema.R b/R/schema.R index d7856ef..46453ef 100644 --- a/R/schema.R +++ b/R/schema.R @@ -43,19 +43,31 @@ getDatabaseSchema <- function( { sqlDialect <- ifelse(isMySQL(db), "mysql", "msaccess") - if (is.null(tableNames)) { + tableInfo <- hsTables(db, namesOnly = FALSE) + + if (! is.null(tableTypes)) { - tableInfo <- hsTables(db, namesOnly = FALSE) types <- kwb.utils::selectColumns(tableInfo, "TABLE_TYPE") + tableInfo <- tableInfo[types %in% tableTypes, ] - tableNames <- sort(kwb.utils::selectColumns(tableInfo, "TABLE_NAME")) + } + + tNames <- kwb.utils::selectColumns(tableInfo, "TABLE_NAME") + + tableNames <- if (is.null(tableNames)) { + + tNames + + } else { + + intersect(tableNames, tNames) } databaseSchema <- list(tables = list()) - for (tableName in tableNames) { + for (tableName in sort(tableNames)) { - cat("Analysing schema of table", tableName, "...\n") + cat("Analysing schema of table/view", tableName, "...\n") tableSchema <- .getTableSchema( db = db, From 94895ae42350d2c6722b5dc4fd19f2ba31b3e857 Mon Sep 17 00:00:00 2001 From: hsonne Date: Mon, 12 Oct 2020 14:31:04 +0200 Subject: [PATCH 08/14] Add argument "as.is" to dumpDatabase() --- NEWS | 1 + R/dumpDatabase.R | 9 +++++++-- man/dumpDatabase.Rd | 6 ++++++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/NEWS b/NEWS index e640e4e..da76241 100644 --- a/NEWS +++ b/NEWS @@ -2,6 +2,7 @@ Latest changes ============== * getDatabaseSchema(): add arguments "tableNames", "tableTypes" +* dumpDatabase(): add argument "as.is" Changes in kwb.db 0.5.0 (2020-06-19) ==================================== diff --git a/R/dumpDatabase.R b/R/dumpDatabase.R index 5c3c50b..d60c391 100644 --- a/R/dumpDatabase.R +++ b/R/dumpDatabase.R @@ -48,13 +48,18 @@ hsDumpMdb <- function( #' @param qmethod passed to \code{\link[utils]{write.table}} #' @param row.names passed to \code{\link[utils]{write.table}} #' @param \dots further arguments passed to \code{\link[utils]{write.table}} +#' @param as.is passed to \code{\link[RODBC]{sqlGetResults}}. If \code{TRUE} +#' (the default is \code{FALSE}), original data types are kept when the table +#' is read into R. By default the types are converted to appropriate R data +#' types (e.g. dates are converted from strings to date objects). #' @importFrom kwb.utils createDirectory safePath #' @importFrom utils write.table #' @export #' dumpDatabase <- function( db, pattern = "^tbl", target_dir = NULL, create_target_dir = FALSE, - sep = ",", dec = ".", qmethod = "double", row.names = FALSE, ... + sep = ",", dec = ".", as.is = FALSE, qmethod = "double", row.names = FALSE, + ... ) { if (is.null(target_dir)) { @@ -78,7 +83,7 @@ dumpDatabase <- function( for (table in tables) { - table_data <- hsGetTable(db, table) + table_data <- hsGetTable(db, table, as.is = as.is) file <- file.path(target_dir, paste0(table, ".csv")) diff --git a/man/dumpDatabase.Rd b/man/dumpDatabase.Rd index 0acfe47..04ecc6b 100644 --- a/man/dumpDatabase.Rd +++ b/man/dumpDatabase.Rd @@ -11,6 +11,7 @@ dumpDatabase( create_target_dir = FALSE, sep = ",", dec = ".", + as.is = FALSE, qmethod = "double", row.names = FALSE, ... @@ -33,6 +34,11 @@ created if it does not exist.} \item{dec}{passed to \code{\link[utils]{write.table}}} +\item{as.is}{passed to \code{\link[RODBC]{sqlGetResults}}. If \code{TRUE} +(the default is \code{FALSE}), original data types are kept when the table +is read into R. By default the types are converted to appropriate R data +types (e.g. dates are converted from strings to date objects).} + \item{qmethod}{passed to \code{\link[utils]{write.table}}} \item{row.names}{passed to \code{\link[utils]{write.table}}} From 82a60355f948df1359b22540a1201658577ddf47 Mon Sep 17 00:00:00 2001 From: hsonne Date: Tue, 13 Oct 2020 13:55:48 +0200 Subject: [PATCH 09/14] Do not stop too early in hsFields() Try to run RODBC::sqlColumns() in any case --- NEWS | 1 + R/hsFields.R | 20 ++++++++++++++++---- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/NEWS b/NEWS index da76241..33585ee 100644 --- a/NEWS +++ b/NEWS @@ -3,6 +3,7 @@ Latest changes * getDatabaseSchema(): add arguments "tableNames", "tableTypes" * dumpDatabase(): add argument "as.is" +* hsFields(): Try RODBC::sqlColumns() before raising an error Changes in kwb.db 0.5.0 (2020-06-19) ==================================== diff --git a/R/hsFields.R b/R/hsFields.R index 204ff47..6beeef1 100644 --- a/R/hsFields.R +++ b/R/hsFields.R @@ -80,10 +80,22 @@ hsFields <- function( tbl <- sub("\\$$", "", tbl) } - fieldInfo <- if (is64BitR()) { - clean_stop("Sorry. There is no equivalent to sqlColumns() in odbc32!") - } else { - RODBC::sqlColumns(con, tbl) + fieldInfo <- try(RODBC::sqlColumns(con, tbl)) + + if (inherits(fieldInfo, "try-error")) { + + msg <- paste("Error when calling RODBC::sqlColumns():", fieldInfo) + + if (is64BitR()) { + + msg <- paste0( + msg, "\nYou are using the 64 bit version of R. You may try to run the ", + "32 bit version of R. Unfortunately there is no equivalent to ", + "sqlColumns() in odbc32." + ) + } + + clean_stop(msg) } if (namesOnly) { From 0f539a75a938aba115f142dd6cf74b47eb7e5282 Mon Sep 17 00:00:00 2001 From: hsonne Date: Sun, 7 Mar 2021 04:33:31 +0100 Subject: [PATCH 10/14] Extend the path to prevent connection error Otherwise you get an error like below when trying to connect to a path containing tilde, as e.g. in "~/tmp/test.accdb" This hopefully closes #9 Error message (acutally a warning that only later leads to an error): [RODBC] FEHLER: Status HY000, Code 63, Nachricht [Microsoft][ODBC Microsoft Access Driver]General error Unable to open registry key Temporary (volatile) Ace DSN for process --- R/connect.R | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/R/connect.R b/R/connect.R index 905a435..86a0e10 100644 --- a/R/connect.R +++ b/R/connect.R @@ -86,7 +86,7 @@ hsOpenDb <- function( if (mode(src) != "character" || length(src) > 1) clean_stop( "src must be a character vector of length one." ) - + ## Open database connection con <- openAdequateConnectionOrStop( src, use2007Driver = use2007Driver, DBMSencoding = DBMSencoding, ... @@ -135,9 +135,9 @@ openAdequateConnectionOrStop <- function( is_mdb <- isAccessFile(db) is_xls <- isExcelFile(db) - # Check the file path if it looks like a MS Access or MS Excel file + # Extend and check the path if it looks like a MS Access or MS Excel file if (is_mdb || is_xls) { - kwb.utils::safePath(db) + db <- kwb.utils::safePath(path.expand(db)) } if (is_mdb) return(odbcConnectionAccess( From 012ce47222006cd29d3f883215e4bc5e09f34711 Mon Sep 17 00:00:00 2001 From: hsonne Date: Sun, 7 Mar 2021 05:05:44 +0100 Subject: [PATCH 11/14] Use the correct term in the comment --- R/connect.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/connect.R b/R/connect.R index 86a0e10..1e99dfc 100644 --- a/R/connect.R +++ b/R/connect.R @@ -135,7 +135,7 @@ openAdequateConnectionOrStop <- function( is_mdb <- isAccessFile(db) is_xls <- isExcelFile(db) - # Extend and check the path if it looks like a MS Access or MS Excel file + # Expand and check the path if it looks like a MS Access or MS Excel file if (is_mdb || is_xls) { db <- kwb.utils::safePath(path.expand(db)) } From ead8fa8edd99300413918d360e1d18bdbb7490eb Mon Sep 17 00:00:00 2001 From: mrustl Date: Wed, 7 Jul 2021 12:46:54 +0200 Subject: [PATCH 12/14] Move to GitHub actions --- .Rbuildignore | 1 + .github/workflows/R-CMD-check.yaml | 81 ++++++++++++++++++++++++++++ .github/workflows/pkgdown.yaml | 49 +++++++++++++++++ .github/workflows/pr-commands.yaml | 51 ++++++++++++++++++ .github/workflows/test-coverage.yaml | 48 +++++++++++++++++ .gitlab-ci.yml | 10 ---- .travis.yml | 31 ----------- LICENSE | 2 +- LICENSE.md | 2 +- README.md | 5 +- _pkgdown.yaml | 2 + appveyor.yml | 67 ----------------------- index.md | 5 +- 13 files changed, 240 insertions(+), 114 deletions(-) create mode 100644 .github/workflows/R-CMD-check.yaml create mode 100644 .github/workflows/pkgdown.yaml create mode 100644 .github/workflows/pr-commands.yaml create mode 100644 .github/workflows/test-coverage.yaml delete mode 100644 .gitlab-ci.yml delete mode 100644 .travis.yml delete mode 100644 appveyor.yml diff --git a/.Rbuildignore b/.Rbuildignore index 9fac54a..4699563 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -10,3 +10,4 @@ LICENSE\.md$ .gitlab-ci.yml ^index\.md$ ^\.travis\.yml$ +^\.github$ diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml new file mode 100644 index 0000000..909fbdf --- /dev/null +++ b/.github/workflows/R-CMD-check.yaml @@ -0,0 +1,81 @@ +on: + push: + branches: + - master + - main + - dev + pull_request: + branches: + - master + - main + - dev + +name: R-CMD-check + +jobs: + R-CMD-check: + runs-on: ${{ matrix.config.os }} + + name: ${{ matrix.config.os }} (${{ matrix.config.r }}) + + strategy: + fail-fast: false + matrix: + config: + - {os: macOS-latest, r: 'release'} + - {os: ubuntu-20.04, r: 'release', rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"} + - {os: windows-latest, r: 'devel'} + - {os: windows-latest, r: 'oldrel'} + - {os: windows-latest, r: 'release'} + + env: + R_REMOTES_NO_ERRORS_FROM_WARNINGS: true + RSPM: ${{ matrix.config.rspm }} + + steps: + - uses: actions/checkout@v2 + + - uses: r-lib/actions/setup-r@master + with: + r-version: ${{ matrix.config.r }} + + - uses: r-lib/actions/setup-pandoc@master + + - name: Query dependencies + run: | + install.packages('remotes') + saveRDS(remotes::dev_package_deps(dependencies = TRUE), "depends.Rds", version = 2) + shell: Rscript {0} + + - name: Cache R packages + if: runner.os != 'Windows' + uses: actions/cache@v1 + with: + path: ${{ env.R_LIBS_USER }} + key: ${{ runner.os }}-r-${{ matrix.config.r }}-3-${{ hashFiles('depends.Rds') }} + restore-keys: ${{ runner.os }}-r-${{ matrix.config.r }}-3- + + - name: Install system dependencies + if: runner.os == 'Linux' + env: + RHUB_PLATFORM: linux-x86_64-ubuntu-gcc + run: | + Rscript -e "remotes::install_github('r-hub/sysreqs')" + sysreqs=$(Rscript -e "cat(sysreqs::sysreq_commands('DESCRIPTION'))") + sudo -s eval "$sysreqs" + - name: Install dependencies + run: | + remotes::install_deps(dependencies = TRUE) + remotes::install_cran("rcmdcheck") + shell: Rscript {0} + + - name: Check + run: rcmdcheck::rcmdcheck(args = "--no-manual", error_on = "warning", check_dir = "check") + shell: Rscript {0} + + - name: Upload check results + if: failure() + uses: actions/upload-artifact@master + with: + name: ${{ runner.os }}-r${{ matrix.config.r }}-results + path: check diff --git a/.github/workflows/pkgdown.yaml b/.github/workflows/pkgdown.yaml new file mode 100644 index 0000000..58a9d79 --- /dev/null +++ b/.github/workflows/pkgdown.yaml @@ -0,0 +1,49 @@ +on: + push: + branches: + - main + - master + - dev + +name: pkgdown + +jobs: + pkgdown: + runs-on: macOS-latest + env: + GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} + steps: + - uses: actions/checkout@v2 + + - uses: r-lib/actions/setup-r@master + + - uses: r-lib/actions/setup-pandoc@master + + - name: Query dependencies + run: | + install.packages('remotes') + saveRDS(remotes::dev_package_deps(dependencies = TRUE), ".github/depends.Rds", version = 2) + writeLines(sprintf("R-%i.%i", getRversion()$major, getRversion()$minor), ".github/R-version") + shell: Rscript {0} + + - name: Cache R packages + uses: actions/cache@v2 + with: + path: ${{ env.R_LIBS_USER }} + key: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-${{ hashFiles('.github/depends.Rds') }} + restore-keys: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1- + + - name: Install dependencies + run: | + remotes::install_deps(dependencies = TRUE) + install.packages("pkgdown", type = "binary") + shell: Rscript {0} + + - name: Install package + run: R CMD INSTALL . + + - name: Deploy package + run: | + git config --local user.email "actions@github.com" + git config --local user.name "GitHub Actions" + Rscript -e 'pkgdown::deploy_to_branch(new_process = FALSE)' diff --git a/.github/workflows/pr-commands.yaml b/.github/workflows/pr-commands.yaml new file mode 100644 index 0000000..0d3cb71 --- /dev/null +++ b/.github/workflows/pr-commands.yaml @@ -0,0 +1,51 @@ +on: + issue_comment: + types: [created] +name: Commands +jobs: + document: + if: startsWith(github.event.comment.body, '/document') + name: document + runs-on: macOS-latest + env: + GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} + steps: + - uses: actions/checkout@v2 + - uses: r-lib/actions/pr-fetch@master + with: + repo-token: ${{ secrets.GITHUB_TOKEN }} + - uses: r-lib/actions/setup-r@master + - name: Install dependencies + run: Rscript -e 'install.packages(c("remotes", "roxygen2"))' -e 'remotes::install_deps(dependencies = TRUE)' + - name: Document + run: Rscript -e 'roxygen2::roxygenise()' + - name: commit + run: | + git add man/\* NAMESPACE + git commit -m 'Document' + - uses: r-lib/actions/pr-push@master + with: + repo-token: ${{ secrets.GITHUB_TOKEN }} + style: + if: startsWith(github.event.comment.body, '/style') + name: style + runs-on: macOS-latest + env: + GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} + steps: + - uses: actions/checkout@v2 + - uses: r-lib/actions/pr-fetch@master + with: + repo-token: ${{ secrets.GITHUB_TOKEN }} + - uses: r-lib/actions/setup-r@master + - name: Install dependencies + run: Rscript -e 'install.packages("styler")' + - name: Style + run: Rscript -e 'styler::style_pkg()' + - name: commit + run: | + git add \*.R + git commit -m 'Style' + - uses: r-lib/actions/pr-push@master + with: + repo-token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/test-coverage.yaml b/.github/workflows/test-coverage.yaml new file mode 100644 index 0000000..4efc7ab --- /dev/null +++ b/.github/workflows/test-coverage.yaml @@ -0,0 +1,48 @@ +on: + push: + branches: + - master + - main + pull_request: + branches: + - master + - main + +name: test-coverage + +jobs: + test-coverage: + runs-on: macOS-latest + env: + GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} + steps: + - uses: actions/checkout@v2 + + - uses: r-lib/actions/setup-r@master + + - uses: r-lib/actions/setup-pandoc@master + + - name: Query dependencies + run: | + install.packages('remotes') + saveRDS(remotes::dev_package_deps(dependencies = TRUE), ".github/depends.Rds", version = 2) + writeLines(sprintf("R-%i.%i", getRversion()$major, getRversion()$minor), ".github/R-version") + shell: Rscript {0} + + - name: Cache R packages + uses: actions/cache@v1 + with: + path: ${{ env.R_LIBS_USER }} + key: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-${{ hashFiles('.github/depends.Rds') }} + restore-keys: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1- + + - 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} diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml deleted file mode 100644 index 3fa71c8..0000000 --- a/.gitlab-ci.yml +++ /dev/null @@ -1,10 +0,0 @@ -pages: - script: - - mv docs public - artifacts: - paths: - - public - only: - - master - - diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index d306eb4..0000000 --- a/.travis.yml +++ /dev/null @@ -1,31 +0,0 @@ -############################################################################## -### Autogenerated with R package kwb.pkgbuild v0.1.1 -### (installed from 'Github (kwb-r/kwb.pkgbuild@0ac3694)' source code on 2019-09-06) -### by calling the function kwb.pkgbuild::use_travis() -### (file created at: 2019-09-06 15:48:52) -############################################################################## - - -language: r -sudo: required -cache: packages -r_packages: -- remotes -- covr -matrix: - include: - - r: devel - - r: release - after_success: - - Rscript -e 'covr::codecov()' - before_deploy: - - Rscript -e 'remotes::install_cran("pkgdown")' - deploy: - provider: script - script: Rscript -e 'pkgdown::deploy_site_github(verbose = TRUE)' - skip_cleanup: 'true' - on: - branch: - - master - - dev - - r: oldrel diff --git a/LICENSE b/LICENSE index f0fe8fd..c56ada2 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2014-2019 Kompetenzzentrum Wasser Berlin gGmbH (KWB) +Copyright (c) 2014-2021 Kompetenzzentrum Wasser Berlin gGmbH (KWB) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/LICENSE.md b/LICENSE.md index 9284dbd..2c4aa3a 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -1,6 +1,6 @@ # MIT License -Copyright (c) 2014-2019 Kompetenzzentrum Wasser Berlin gGmbH (KWB) +Copyright (c) 2014-2021 Kompetenzzentrum Wasser Berlin gGmbH (KWB) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index 2409edf..f1b6d90 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,6 @@ -[![Appveyor build status](https://ci.appveyor.com/api/projects/status/m70gtm2010x6hnqi/branch/master?svg=true)](https://ci.appveyor.com/project/KWB-R/kwb-db/branch/master) -[![Build Status](https://travis-ci.org/KWB-R/kwb.db.svg?branch=master)](https://travis-ci.org/KWB-R/kwb.db) [![codecov](https://codecov.io/github/KWB-R/kwb.db/branch/master/graphs/badge.svg)](https://codecov.io/github/KWB-R/kwb.db) [![lifecycle](https://img.shields.io/badge/lifecycle-stable-brightgreen.svg)](https://www.tidyverse.org/lifecycle/#stable) +[![R-CMD-check](https://github.com/KWB-R/kwb.db/workflows/R-CMD-check/badge.svg)](https://github.com/KWB-R/kwb.db/actions?query=workflow%3AR-CMD-check) +[![pkgdown](https://github.com/KWB-R/kwb.db/workflows/pkgdown/badge.svg)](https://github.com/KWB-R/kwb.db/actions?query=workflow%3Apkgdown) +[![codecov](https://codecov.io/github/KWB-R/kwb.db/branch/master/graphs/badge.svg)](https://codecov.io/github/KWB-R/kwb.db) [![lifecycle](https://img.shields.io/badge/lifecycle-stable-brightgreen.svg)](https://www.tidyverse.org/lifecycle/#stable) # kwb.db diff --git a/_pkgdown.yaml b/_pkgdown.yaml index 473126d..690c2df 100644 --- a/_pkgdown.yaml +++ b/_pkgdown.yaml @@ -1,4 +1,6 @@ authors: + Hauke Sonnenberg: + href: http://github.com/hsonne Michael Rustler: href: http://mrustl.de Kompetenzzentrum Wasser Berlin gGmbH: diff --git a/appveyor.yml b/appveyor.yml deleted file mode 100644 index 2fef893..0000000 --- a/appveyor.yml +++ /dev/null @@ -1,67 +0,0 @@ -############################################################################## -### Autogenerated with R package kwb.pkgbuild v0.1.1 -### (installed from 'Github (kwb-r/kwb.pkgbuild@0ac3694)' source code on 2019-09-06) -### by calling the function kwb.pkgbuild::use_appveyor() -### (file created at: 2019-09-06 15:48:46) -############################################################################## - - - -### Configuration copied from: -### https://raw.githubusercontent.com/tidyverse/readxl/5649e2643d25bb5b6353797fc48bbcbb0eb72f6d/appveyor.yml" -### But in addition also use two environment variables: -### - USE_RTools = true(for details see: https://github.com/KWB-R/kwb.pkgbuild/issues/37) -### - R_REMOTES_STANDALONE = true (for details see: https://github.com/r-lib/remotes#standalone-mode, https://github.com/krlmlr/r-appveyor/issues/135) - -# DO NOT CHANGE the "init" and "install" sections below - -# Download script file from GitHub -init: - ps: | - $ErrorActionPreference = "Stop" - Invoke-WebRequest http://raw.github.com/krlmlr/r-appveyor/master/scripts/appveyor-tool.ps1 -OutFile "..\appveyor-tool.ps1" - Import-Module '..\appveyor-tool.ps1' - -install: - ps: Bootstrap - -cache: - - C:\RLibrary - -# Adapt as necessary starting from here - -environment: -### Add RTools (for details see: https://github.com/KWB-R/kwb.pkgbuild/issues/37) - USE_RTOOLS: true -### Add R_REMOTES_STANDALONE(for details see: https://github.com/krlmlr/r-appveyor/issues/135 -### or https://github.com/r-lib/remotes#standalone-mode) - R_REMOTES_STANDALONE: true - -build_script: - - travis-tool.sh install_deps - -test_script: - - travis-tool.sh run_tests - -on_failure: - - 7z a failure.zip *.Rcheck\* - - appveyor PushArtifact failure.zip - -artifacts: - - path: '*.Rcheck\**\*.log' - name: Logs - - - path: '*.Rcheck\**\*.out' - name: Logs - - - path: '*.Rcheck\**\*.fail' - name: Logs - - - path: '*.Rcheck\**\*.Rout' - name: Logs - - - path: '\*_*.tar.gz' - name: Bits - - - path: '\*_*.zip' - name: Bits diff --git a/index.md b/index.md index 8610205..1c8b2b6 100644 --- a/index.md +++ b/index.md @@ -1,5 +1,6 @@ -[![Appveyor build status](https://ci.appveyor.com/api/projects/status/m70gtm2010x6hnqi/branch/master?svg=true)](https://ci.appveyor.com/project/KWB-R/kwb-db/branch/master) -[![Build Status](https://travis-ci.org/KWB-R/kwb.db.svg?branch=master)](https://travis-ci.org/KWB-R/kwb.db) [![codecov](https://codecov.io/github/KWB-R/kwb.db/branch/master/graphs/badge.svg)](https://codecov.io/github/KWB-R/kwb.db) [![lifecycle](https://img.shields.io/badge/lifecycle-stable-brightgreen.svg)](https://www.tidyverse.org/lifecycle/#stable) +[![R-CMD-check](https://github.com/KWB-R/kwb.db/workflows/R-CMD-check/badge.svg)](https://github.com/KWB-R/kwb.db/actions?query=workflow%3AR-CMD-check) +[![pkgdown](https://github.com/KWB-R/kwb.db/workflows/pkgdown/badge.svg)](https://github.com/KWB-R/kwb.db/actions?query=workflow%3Apkgdown) +[![codecov](https://codecov.io/github/KWB-R/kwb.db/branch/master/graphs/badge.svg)](https://codecov.io/github/KWB-R/kwb.db) [![lifecycle](https://img.shields.io/badge/lifecycle-stable-brightgreen.svg)](https://www.tidyverse.org/lifecycle/#stable) This repository contains the R package kwb.db. The package provides functions that aim at simplifying the data transfer between databases and R. It is based on the [RODBC](https://cran.r-project.org/web/packages/RODBC/) package that gives access to databases that provide an [ODBC](https://docs.microsoft.com/en-us/sql/odbc/reference/what-is-odbc) interface. Databases may be Microsoft Access files, Microsoft Excel files or any other database that is registered as an ODBC data source on your local machine. See e.g. [here](https://docs.microsoft.com/en-us/sql/odbc/admin/odbc-data-source-administrator) for how to setup ODBC data sources in Windows. From 57af31e94b3a9af1c9e6e3f5957b6af6f792e586 Mon Sep 17 00:00:00 2001 From: mrustl Date: Wed, 7 Jul 2021 12:56:55 +0200 Subject: [PATCH 13/14] Run desc::desc_normalise and prepare v0.6.0 --- DESCRIPTION | 41 +++++++++++++++++++++-------------------- NEWS | 37 ------------------------------------- NEWS.md | 38 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 59 insertions(+), 57 deletions(-) delete mode 100644 NEWS create mode 100644 NEWS.md diff --git a/DESCRIPTION b/DESCRIPTION index cbf39be..1b7db4d 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,18 +1,6 @@ Package: kwb.db -Version: 0.5.0.9000 Title: Functions supporting data base access -Description: This package contains some useful functions, especially for - simplifying data transfer between MS Access databases and R. With the - functions of this package it is not needed any more to open and close a - database connection explicitely; this is done 'behind the scenes' in the - functions. Instead of a database connection the path to the database file - needs to be passed to the functions as an argument. The main functions are - hsGetTable and hsPutTable which transfer data from an MS Access database to - a data frame in R and save data from a data frame in R into a table in an MS - Access database, respectively. Take care when getting time series data from - an MS Access database, see therefore hsMdbTimeSeries. Use hsTables to get a - list of tables that are available in a database and hsFields to get a list - of table fields that are contained in a database table. +Version: 0.6.0 Authors@R: c(person(given = "Hauke", family = "Sonnenberg", @@ -26,6 +14,22 @@ Authors@R: comment = "0000-0003-0647-7726"), person(given = "Kompetenzzentrum Wasser Berlin gGmbH", role = "cph")) +Description: This package contains some useful functions, especially for + simplifying data transfer between MS Access databases and R. With the + functions of this package it is not needed any more to open and close + a database connection explicitely; this is done 'behind the scenes' in + the functions. Instead of a database connection the path to the + database file needs to be passed to the functions as an argument. The + main functions are hsGetTable and hsPutTable which transfer data from + an MS Access database to a data frame in R and save data from a data + frame in R into a table in an MS Access database, respectively. Take + care when getting time series data from an MS Access database, see + therefore hsMdbTimeSeries. Use hsTables to get a list of tables that + are available in a database and hsFields to get a list of table fields + that are contained in a database table. +License: MIT + file LICENSE +URL: https://github.com/KWB-R/kwb.db +BugReports: https://github.com/KWB-R/kwb.db/issues Imports: kwb.datetime (>= 0.4.0), kwb.utils (>= 0.4.4), @@ -34,12 +38,9 @@ Imports: Suggests: testthat (>= 2.2.1) Remotes: - github::kwb-r/kwb.datetime, - github::kwb-r/kwb.utils, - github::hsonne/odbc32@r3.0.0, - github::cran/RODBC@1.3-16 + github::cran/RODBC@1.3-16, + github::hsonne/odbc32@r3.0.0, + github::kwb-r/kwb.datetime, + github::kwb-r/kwb.utils Encoding: UTF-8 -License: MIT + file LICENSE RoxygenNote: 7.1.1 -URL: https://github.com/KWB-R/kwb.db -BugReports: https://github.com/KWB-R/kwb.db/issues diff --git a/NEWS b/NEWS deleted file mode 100644 index 33585ee..0000000 --- a/NEWS +++ /dev/null @@ -1,37 +0,0 @@ -Latest changes -============== - -* getDatabaseSchema(): add arguments "tableNames", "tableTypes" -* dumpDatabase(): add argument "as.is" -* hsFields(): Try RODBC::sqlColumns() before raising an error - -Changes in kwb.db 0.5.0 (2020-06-19) -==================================== -* Try using RODBC functions first before using functions from rodb32 package - (Since some MS Office version there are 64 Bit RODBC drivers available!) -* Export more functions: - + dumpDatabase() - + sqlForSelectByKey() - + sqlForUpdate() - -Changes in kwb.db 0.4.0 (2019-11-03) -==================================== -* Use the package odbc32 by Vaclav Hausenblas in order to use Window's 32 bit - ODBC driver from within a 64 bit R session. -* Decrease the number of exported functions. - TODO: Check if some functions need to be exported again as they may be used - in some scripts that were/are used at KWB. - -2019-06-07 -* give a warning when using deprecated functions hsOpenMdb(), hsCloseMdb() - -2019-06-06 -* support 64 Bit in odbcConnectionAccess() - -Changes in kwb.db 0.1.1 -======================= -* xmdb now points to example database in this package not in kwb.base - -Changes in kwb.db 0.1.0 -======================= -* package created with functions that were originally in kwb.base diff --git a/NEWS.md b/NEWS.md new file mode 100644 index 0000000..052593c --- /dev/null +++ b/NEWS.md @@ -0,0 +1,38 @@ +# [kwb.db 0.6.0](https://github.com/KWB-R/kwb.db/releases/tag/v0.6.0) 2021-07-07 + +* `getDatabaseSchema()`: add arguments "tableNames", "tableTypes" +* `dumpDatabase()`: add argument "as.is" +* `hsFields()`: Try `RODBC::sqlColumns()` before raising an error + +# [kwb.db 0.5.0](https://github.com/KWB-R/kwb.db/releases/tag/v0.5.0) 2020-06-19 + +* Try using RODBC functions first before using functions from rodb32 package + (Since some MS Office version there are 64 Bit RODBC drivers available!) +* Export more functions: + + `dumpDatabase()` + + `sqlForSelectByKey()` + + `sqlForUpdate()` + +# [kwb.db 0.4.0](https://github.com/KWB-R/kwb.db/releases/tag/v0.4.0) 2019-11-03 + +* Use the package odbc32 by Vaclav Hausenblas in order to use Window's 32 bit + ODBC driver from within a 64 bit R session. +* Decrease the number of exported functions. + TODO: Check if some functions need to be exported again as they may be used + in some scripts that were/are used at KWB. + +# kwb.db 0.3.0 (2019-06-07) + +* give a warning when using deprecated functions `hsOpenMdb()`, `hsCloseMdb()` + +# kwb.db 0.2.0 (2019-06-06) + +* support 64 Bit in `odbcConnectionAccess()` + +# kwb.db 0.1.1 + +* xmdb now points to example database in this package not in kwb.base + +# kwb.db 0.1.0 + +* package created with functions that were originally in kwb.base From 8ff36478346769bb7df857fa1ae4c021843048bf Mon Sep 17 00:00:00 2001 From: mrustl Date: Wed, 7 Jul 2021 13:01:36 +0200 Subject: [PATCH 14/14] Simplify linking to functions --- index.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/index.md b/index.md index 1c8b2b6..58398ad 100644 --- a/index.md +++ b/index.md @@ -19,16 +19,16 @@ devtools::install_github("kwb-r/kwb.db", dependencies = TRUE) ## Database Access in RODBC -With the RODBC package, you need to open a database connection, send one or more requests to the database and finally close the dabase connection. +With the RODBC package, you need to open a database connection, send one or more requests to the database and finally close the database connection. ## Database Access with this package With the functions of this package it is not needed to open and close a database connection explicitly; this is done behind the scenes in the functions. Instead of a database connection the path to the database file needs to be passed to the functions as an argument. -The main functions are [`hsGetTable()`](https://kwb-r.github.io/kwb.db/reference/hsGetTable.html) and [`hsPutTable()`](https://kwb-r.github.io/kwb.db/reference/hsPutTable.html). They transfer data from a database to a data frame in R and save data from a data frame in R into a new table in a database, respectively. +The main functions are `hsGetTable()` and `hsPutTable()`. They transfer data from a database to a data frame in R and save data from a data frame in R into a new table in a database, respectively. -Use [`hsTables()`](https://kwb-r.github.io/kwb.db/reference/hsTables.html) to get a list of tables that are available in a database and [`hsFields()`](https://kwb-r.github.io/kwb.db/reference/hsFields.html) to get a list of table fields that are contained in a database table. +Use `hsTables()` to get a list of tables that are available in a database and `hsFields()` to get a list of table fields that are contained in a database table. A general workflow could look like this: @@ -54,4 +54,4 @@ kwb.db::hsPutTable(mdb, data_new, "fancy_table") In each of the `kwb.db::`-function calls above a database connection is opened, a request to the database is sent and the connection is closed again. Thus, the user does not have to care about open database connections. -Take care when getting time series data from an MS Access database, see therefore [`hsMdbTimeSeries()`](https://kwb-r.github.io/kwb.db/reference/hsMdbTimeSeries.html). +Take care when getting time series data from an MS Access database, see therefore `hsMdbTimeSeries()`.