I am relatively new to R coding, and certainly new to connecting data. A colleague left me a script to create a connection between our datawarehouse and R. This datawarehouse brings together several streams of live data. My involvement with the datawarehouse so far has been through queries with PostgreSQL, pgAdmin. However, I am unable to run this R script correctly.
I have pasted the script below. However, it is at point 3 where I find the error (or the first error at least)
this code:
drv <- keyring::key_get("NRAdb-driver", username = "NRADWH")
produces this error:
Error in b_wincred_i_get(target) :
Windows credential store error in 'get': Element not found.
Any help would be great (grateful for any advice on other parts of the script as well)
setup_database_access <- function(database = "NRADWH", host = "10.18.0.250", port = "3128", driver = RPostgres::Postgres())
setup_database_access(database = "NRADWH", host = "10.18.0.250", driver = RPostgres::Postgres())
establish_db_connection <- function(database = "NRADWH") {
stopifnot("Credentials not found. First run 'setup_database_access(...)'" =
database %in% keyring::key_list("NRAdb-username")[["username"]] &
database %in% keyring::key_list("NRAdb-password")[["username"]])
stopifnot("Database mis-configured. Please re-run setup_database_access(...)'" =
database %in% keyring::key_list("NRAdb-driver")[["username"]] &
keyring::key_get("NRAdb-driver", username = database) %in% c("postgres", "mysql"))
}
drv <- keyring::key_get("NRAdb-driver", username = "NRADWH")
if(drv=="postgres"){
driver <- RPostgres::Postgres()
} else if (drv == "mysql") {
driver <- RMariaDB
if (database %in% keyring::key_list("NRAdb-host")[["username"]]){ # retrieve and store the port for use in the connection code
port <- keyring::key_get("NRAdb-port", username = database)
} else {
port <- NULL
}
con <- DBI::dbConnect(drv = driver,
user = keyring::key_get("NRAdb-username", username = databse),
password = keyring::key_get("NRAdb-password", username = database),
host = keyring::key_get("NRAdb-host", username = database),
port = port,
dbname = database)
}
NRADWH <- establish_db_connection("NRADWH")
Bradley Tyler is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.