Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
benyamindsmith opened this issue Dec 31, 2023 · 0 comments
Open

Comments

@benyamindsmith
Copy link

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.

@benyamindsmith benyamindsmith changed the title Incorperating this dependency in an R package Incorperating this package as a dependency in another R package Dec 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant