Skip to contents

Connect to registration database to get all necessary information on data source and cleaning specification. The driver is only applicable to an Access Database. Calling the method KHelse$new(YourFilePath) will create an object of R6 Class. Please refer to the examples.

Public fields

dbname

Database filename.

dbtype

Database type of either Access or DuckDB

dbyear

Production year. Only relevant for DuckDB

dbconn

Database connection.

tblname

Table name to be created in the database.

tblvalue

Data to be inserted in the table tblname. Data must be in a data.frame or data.table format.

dbpath

Database path

conn

Create database connection. Default is TRUE

Methods


Method new()

Start connecting to the database.

Usage

KHelse$new(
  dbname = NULL,
  dbtype = "Access",
  dbyear = NULL,
  dbpath = FALSE,
  conn = TRUE
)

Arguments

dbname

Database filename.

dbtype

Database type eg. Access, SQLite, DuckDB etc.

dbyear

Production year. This arg only relevant to raw database in DuckDB

dbpath

Path to the database file

conn

Create database connection. Default is TRUE

Examples

\dontrun{
kh <- KHelse$new(file.path(getOption("orgdata.drive"),
                           getOption("orgdata.folder.db"),
                           getOption("orgdata.db")))
kh$dbname
kh$db_close()
kh$db_connect()
}


Method db_connect()

Reconnect to the database when db_close was used.

Usage

KHelse$db_connect()


Method db_write()

Write table to the database.

Usage

KHelse$db_write(
  name = NULL,
  value = NULL,
  write = FALSE,
  append = FALSE,
  field.types = NULL
)

Arguments

name

Table name to be created in the database.

value

The data to be inserted in the table.

write

Write a table to the database. It will overwrite the table if it already exists

append

Append the data to an existing table in the database

field.types

Type of data in specified column. Must be named as vector


Method db_read()

Read table and convert to data.table format

Usage

KHelse$db_read(name = NULL)

Arguments

name

Table name to be created in the database.


Method db_remove_table()

Remove table in the database.

Usage

KHelse$db_remove_table(name = NULL)

Arguments

name

Table name to be created in the database.


Method db_close()

Close connection to the database.

Usage

KHelse$db_close()

Examples


## ------------------------------------------------
## Method `KHelse$new`
## ------------------------------------------------

if (FALSE) { # \dontrun{
kh <- KHelse$new(file.path(getOption("orgdata.drive"),
                           getOption("orgdata.folder.db"),
                           getOption("orgdata.db")))
kh$dbname
kh$db_close()
kh$db_connect()
} # }