OHDSI Home | Forums | Wiki | Github

Example of 9.2.1 in OHDSI book

Hello OHDSI members,

I am a recent member and studying CDM codes with OHDSI book, but 9.2.1 code does not execute in R.

conn <- connect(dbms = "postgresql",
                server = "localhost/postgres",
                user = "joe",
                password = "secret",
                schema = "cdm")

I installed and import DatabaseConnector library.
However, R cannot execute connect function.
The error message is below:

Error in connect(dbms = "postgresql", server = "localhost/postgres", user = "joe",  : 
  unused argument (schema = "cdm")

I also referred to documents about connect function and its description does not show the schema argument now.

Description
connect creates a connection to a database server .There are four ways to call this function:

  • connect(dbms, user, password, server, port, extraSettings, oracleDriver, pathToDriver)
  • connect(connectionDetails)
  • connect(dbms, connectionString, pathToDriver))
  • connect(dbms, connectionString, user, password, pathToDriver)

If you have the new code for solving the error, please let me know it.

Thank you in advance.

Hi @Inho !
Welcome to OHDSI and our community!
Thanks for posting your question.

This example from the book shows how one would connect to a database that you have set up or are trying to access.
All the values for each of the fields in connect, i.e. dbms, server, user, password, and schema, are simply examples.
You would need the correct credentials for your own database to get things set up with your values for each of the fields, respectively.

If you do not have a database setup yet, I would strongly suggest you use the Eunomia package made by @cce.
Using this package, you can follow along with the tutorials, but instead, use the connection details for Eunomia in place of what the book is suggesting.
Here is the relevant code to look at:

library(DatabaseConnector)
library(Eunomia)
connectionDetails <- getEunomiaConnectionDetails()
connection <- connect(connectionDetails)
querySql(connection, "SELECT COUNT(*) FROM person;")
#  COUNT(*)
#1     2694

getTableNames(connection,databaseSchema = 'main')
disconnect(connection)

Hope this helps - let us know if you have any more questions.

~ tcp :deciduous_tree:

@TheCedarPrince

Thank you for your kindly reply.
I tried your suggestion, but I cannot install the Eunomia package.

R shows the error message below:

Warning in install.packages :
  package β€˜Eunomia’ is not available for this version of R

A version of this package for your version of R might be available elsewhere,
see the ideas at
https://cran.r-project.org/doc/manuals/r-patched/R-admin.html#Installing-packages

I referred to the URL and tried getOption and av, but I could not solve my problem.
I cannot find the Eunomia package in the av list on R data, and R cannot install the package with this error message.

getOption("repos")
                       CRAN 
"https://cran.rstudio.com/" 
attr(,"RStudio")
[1] TRUE

av <- available.packages(filters=list())

av[av[, "Package"] == Eunomia, ]
Error: object 'Eunomia' not found

I also visited old Eunomia and Eunomia archive.
However, I do not know next process, and when I access one Flavor, 404 Error is displayed.

What is my next step to solving the problem?

The question is changed from CDM to the technical problem of R, but I look forward to your next response.

Thank you very much! :smiley:

Yes, I agree - it is an R problem.
I have seen this issue before.
Rather than installing via CRAN, try this instead:

install.packages("remotes")
library("remotes")
remotes::install_github("OHDSI/Eunomia")

And that should install the library properly to your machine.
Not sure why this error occurs exactly but I believe it is fixed in the main package hosted on GitHub.
Let me know if this works for you @Inho. :slight_smile:

@TheCedarPrince

You did it! :wink:

But, I am facing the original challenge again that I asked at first.
I installed Eunomia package successfully and I did a database setup as directed by your answers.

> library(Eunomia)
ν•„μš”ν•œ νŒ¨ν‚€μ§€λ₯Ό λ‘œλ”©μ€‘μž…λ‹ˆλ‹€: DatabaseConnector
> connectionDetails <- getEunomiaConnectionDetails()
> connection <- connect(connectionDetails)
Connecting using SQLite driver
> querySql(connection, "SELECT COUNT(*) FROM person;")
  COUNT(*)
1     2694
> 
> getTableNames(connection,databaseSchema = 'main')
 [1] "CARE_SITE"             "CDM_SOURCE"            "COHORT"               
 [4] "COHORT_ATTRIBUTE"      "CONCEPT"               "CONCEPT_ANCESTOR"     
 [7] "CONCEPT_CLASS"         "CONCEPT_RELATIONSHIP"  "CONCEPT_SYNONYM"      
[10] "CONDITION_ERA"         "CONDITION_OCCURRENCE"  "COST"                 
[13] "DEATH"                 "DEVICE_EXPOSURE"       "DOMAIN"               
[16] "DOSE_ERA"              "DRUG_ERA"              "DRUG_EXPOSURE"        
[19] "DRUG_STRENGTH"         "FACT_RELATIONSHIP"     "LOCATION"             
[22] "MEASUREMENT"           "METADATA"              "NOTE"                 
[25] "NOTE_NLP"              "OBSERVATION"           "OBSERVATION_PERIOD"   
[28] "PAYER_PLAN_PERIOD"     "PERSON"                "PROCEDURE_OCCURRENCE" 
[31] "PROVIDER"              "RELATIONSHIP"          "SOURCE_TO_CONCEPT_MAP"
[34] "SPECIMEN"              "VISIT_DETAIL"          "VISIT_OCCURRENCE"     
[37] "VOCABULARY"           
> conn <- connect(dbms = "PostgreSQL", server = "localhost/postgres", user = "joe", password = "secret", schema = "cdm")
Error in connect(dbms = "postgresql", server = "localhost/postgres", user = "joe",  : 
  unused argument (schema = "cdm")

You can see the error message in the last line above.
I could not know why it did not work, so I passed the problem and tried the next example in the book below.

connString <- "jdbc:postgresql://localhost:5432/postgres"
conn <- connect(dbms = "postgresql",
                connectionString = connString,
                user = "joe",
                password = "secret",
                schema = "cdm")

However, R printed the same error message.

Error in connect(dbms = "postgresql", connectionString = connString, user = "joe",  : 
  unused argument (schema = "cdm")

I am a data analyst so I only have analyzed the data that is extracted by a data engineer, so I am unaccustomed to a work-related database, while I know its concept.
But now, I should know the CDM system, so I want to get over this difficulty.

Hey @Inho

Ah, I see where you are getting this error.
Eunomia is for if you do not have your own database as I was saying earlier:

So, in this case to do the exercises, skip where it asks you to make a connection like you have been trying to do here:

It will error because you do not have a database with those credentials set up.
So, using Eunomia instead, skip section 9.2.1 and move forward with the code you wrote here:

And whenever you see in the examples the variable, conn used, just use the connection variable you defined here instead.
For example, to do the exercise 9.2.2, this is how your code should look:

querySql(connection , "SELECT TOP 3 * FROM person")

Here, we are using the connection to Eunomia first.
If you need to use a real database that you own besides Eunomia, you will need to reach out to your data engineer for the credentials to create a connection.

Does that help clarify things?

@TheCedarPrince

Perfect! I understand completely.
I guessed the problem is related to the network system something but I could not be sure.
I just start working as a data analyst, and a CDM administrator at the same time in my new division recently.
The result of our long communication makes me understand the CDM system better.
When I meet another problem, (but I do not want to meet serious errors), I will visit here again.

Thank you very much, @TheCedarPrince! :wink:

1 Like

Amazing and best of luck @Inho !
Welcome to the community. :slight_smile:

t