Skip to content

Incorperating this package as a dependency in another R package #133

@benyamindsmith

Description

@benyamindsmith

I am using this package as a dependency for a personal project and I am struggling with how to incorperate this package dependency without having to put library(RPostgreSQL) in the function code.

For some context, the code that I uses connects to a PostgreSQL database hosted on the cloud and proceeds to preform some relevant queries.

My code:

database_func<- function(
    dsn_database,
    dsn_hostname,
    dsn_port,
    dsn_uid,
    dsn_pwd,
    ...) {



  tryCatch({
    drv <- dbDriver("PostgreSQL")
    print("Connecting to Database…")
    connec <- dbConnect(drv,
                        dbname = dsn_database,
                        host = dsn_hostname,
                        port = dsn_port,
                        user = dsn_uid,
                        password = dsn_pwd)
    print("Database Connected!")
  },
  error=function(cond) {
    print("Unable to connect to Database.")
  })

# REST OF CODE ....

}

If I don't call library(RPostgreSQL) before I utilize this function, the code breaks as the argument for dbDriver() is invalid.

I tried having RPostGreSQL listed in my package dependencies in my DESCRIPTION file but the problem still persists.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions