Introduction

The purpose of this document is to document the techniques for updating the risk analysis test data used in this package.

Manual Export Using SQL Develoer

This section describes how to process data manually exported from SQLDeveloper.

library(stringr)
library(readr)
library(DBI)
library(ROracle)
library(keyring)

Automatic Update Using ROracle

This section describes how to make a direct connection to the project Oracle database and export the data tables from this connection.

# Use the `keyring` package to save the database username and password in the 
# system credential store
key_service <- "egis-db-brandonroad"
user_name <- "BrandonRoad"
# Set once on each computer prior to building book
# keyring::key_set(service = key_service, username = user_name)

# Make Oracle connection
drv  <- DBI::dbDriver("Oracle")
host <- "egis-db"
port <- "1521"
sid  <- "B5SDEDP1"
connect_string <- paste0(
  "(DESCRIPTION=",
  "(ADDRESS=(PROTOCOL=tcp)(HOST=", host, ")(PORT=", port, "))",
  "(CONNECT_DATA=(SID=", sid, ")))")

con_roracle <- ROracle::dbConnect(drv, 
                                  username = user_name, 
                                  password = key_get(key_service, user_name),
                                  dbname   = connect_string)
# Import tables from Oracle
db_risk              <- ROracle::dbReadTable(con_roracle, 
                                             "RISK_MAIN_VIEW")
db_events            <- ROracle::dbReadTable(con_roracle, 
                                             "EVENTS_MAIN_VIEW")
db_discussion        <- ROracle::dbReadTable(con_roracle, 
                                             "DISCUSSION_LOG_MAIN_VIEW")
db_action            <- ROracle::dbReadTable(con_roracle, 
                                             "ACTION_MAIN_VIEW")
db_decision          <- ROracle::dbReadTable(con_roracle, 
                                             "DECISION_MAIN_VIEW")
db_rel_action_action <- ROracle::dbReadTable(con_roracle, 
                                             "REL_ACTION_ACTION_MAIN_VIEW")
db_rel_dec_dec       <- ROracle::dbReadTable(con_roracle, 
                                             "REL_DEC_DEC_MAIN_VIEW")
db_rel_dec_action    <- ROracle::dbReadTable(con_roracle, 
                                             "REL_DEC_ACTION_MAIN_VIEW")
db_rel_risk_action   <- ROracle::dbReadTable(con_roracle, 
                                             "REL_RISK_ACTION_MAIN_VIEW")
db_rel_risk_dec      <- ROracle::dbReadTable(con_roracle, 
                                             "REL_RISK_DEC_MAIN_VIEW")
db_rel_risk_risk     <- ROracle::dbReadTable(con_roracle, 
                                             "REL_RISK_RISK_MAIN_VIEW")

# Disconnect from the database
ROracle::dbDisconnect(con_roracle)
usethis::use_data(db_risk,
                  db_events,
                  db_discussion,
                  db_action,
                  db_decision,
                  db_rel_action_action,
                  db_rel_dec_dec,
                  db_rel_dec_action,
                  db_rel_risk_action,
                  db_rel_risk_dec,
                  db_rel_risk_risk,
                  overwrite = TRUE)


MVR-GIS/rarr documentation built on March 4, 2023, 11:47 p.m.