0

I am trying to connect to a database to read a table to R, but it is giving me connection timeout errors at times. I have tried changing the connection attributes, but nothing worked 100 percent of the time. Is there a way to run the code multiple times until a data frame is created?.

This is the code sample I am using to read the table and it works most of the time, but I would like this code to run multiple times until it connects and creates the required dataframe.

Dataframe <- dataset.load(name = "Connection name", query = paste("Select * from table"),connect_params=list(socketTimeout=100, loginTimeout=100))
  • Maybe using `while`? https://stackoverflow.com/questions/20507247/r-repeat-function-until-condition-met – Skaqqs Dec 16 '21 at 18:19
  • I am new to R, so I am trying to figure out the best way to do it. Thanks for your response. – Jeffin Jacob Dec 16 '21 at 18:28
  • Great, welcome! Can you share all the code that you are using? What package does `dataset.load()` come from? It is difficult to assist without being able to recreate the issue. – Skaqqs Dec 16 '21 at 21:19
  • Thanks for the response Skaggs. dataset.load() is an internal package to load tables from the RDW. The only change would be the connection name and table name. Everything else is exactly the same that I have been using to read the table. I need a way to run that piece of code continuously until the "Dataframe" is created" – Jeffin Jacob Dec 17 '21 at 16:28
  • How about `Dataframe <- data.frame(); while(nrow(dataframe)==0){Dataframe <- dataset.load(name="Connection name", query=paste("Select * from table"), connect_params=list(socketTimeout=100, loginTimeout=100))}` – Skaqqs Dec 17 '21 at 16:33

0 Answers0