Insatllation and set up of R6 rocker object

Nikolaus Pawlowski


Installation

Installation of current released version from CRAN

install.packages("rocker")

Installation of current development version from GitHub

install.packages("devtools")
devtools::install_github("nikolaus77/rocker")

New rocker class object

Create new rocker database handling object

Option 1

db <- rocker::newDB() # New database handling object
#> dctr | New object

Option 2

db <- rocker::rocker$new() # New database handling object
#> dctr | New object

Terminal output

Controlling terminal output

db <- rocker::newDB(verbose = TRUE) # New database handling object
#> dctr | New object
db$setupPostgreSQL()
#> Dctr | Driver load RPostgres
db$unloadDriver()
#> dctr | Driver unload RPostgres
db$verbose <- FALSE # Terminal output off
db$setupPostgreSQL()
db$unloadDriver()
db$verbose <- TRUE # Terminal output on (default)
db$setupPostgreSQL()
#> Dctr | Driver load RPostgres
db$unloadDriver()
#> dctr | Driver unload RPostgres

Structure of terminal output

Dctr | Driver load RSQLite
D                          = Driver     (D = loaded,    d = not set)
 c                         = Connection (C = opened,    c = closed)
  t                        = Transation (T = active,    t = no tranastion)
   r                       = Result     (R = available, r = no result)
       Driver load RSQLite = Message text

Optional object ID

Optionally, rocker object can be labeled with an ID. This can be helpful in case terminal output of multiple rocker objects need to be distinguished.

db1 <- rocker::newDB(id = "myDB 1") # New database handling object with ID
#> myDB 1 | dctr | New object id myDB 1
db2 <- rocker::newDB(id = "myDB 2") # New database handling object with ID
#> myDB 2 | dctr | New object id myDB 2
db1$setupPostgreSQL()
#> myDB 1 | Dctr | Driver load RPostgres
db2$setupMariaDB()
#> myDB 2 | Dctr | Driver load RMariaDB
db1$unloadDriver()
#> myDB 1 | dctr | Driver unload RPostgres
db2$unloadDriver()
#> myDB 2 | dctr | Driver unload RMariaDB
db1$id <- NULL # Remove ID
db1$setupSQLite()
#> Dctr | Driver load RSQLite
db1$unloadDriver()
#> dctr | Driver unload RSQLite
db1$id <- "newID 1" # Add new ID
db1$setupSQLite()
#> newID 1 | Dctr | Driver load RSQLite
db1$unloadDriver()
#> newID 1 | dctr | Driver unload RSQLite

Object properties

Object properties are stored in the info field and can be displayed by print function.

db <- rocker::newDB() # New database handling object
#> dctr | New object
db$setupPostgreSQL()
#> Dctr | Driver load RPostgres
db$info
#> $package
#> [1] "RPostgres"
#> 
#> $host
#> [1] "127.0.0.1"
#> 
#> $port
#> [1] "5432"
#> 
#> $dbname
#> [1] "mydb"
db
#> id          null
#> package     RPostgres
#> host        127.0.0.1
#> port        5432
#> dbname      mydb
#> driver      true
#> connection  false
#> transaction false
#> result      false
#> verbose     true
db$print()
#> id          null
#> package     RPostgres
#> host        127.0.0.1
#> port        5432
#> dbname      mydb
#> driver      true
#> connection  false
#> transaction false
#> result      false
#> verbose     true
print(db)
#> id          null
#> package     RPostgres
#> host        127.0.0.1
#> port        5432
#> dbname      mydb
#> driver      true
#> connection  false
#> transaction false
#> result      false
#> verbose     true
db$unloadDriver()
#> dctr | Driver unload RPostgres

Further help

Please read the documentation of rocker class.

help(rocker)

Reading of DBI package documentation is recommended.