Successfully recorded bank warning - R

Asked

Viewed 47 times

-2

Hello! I am currently recording/updating my tables in the database with the R language:

dbWriteTable(con, "tabela",tabela, row.names=FALSE, overwrite = TRUE)

This my script that updates the tables in R in a postgres database, is run automatically from time to time by a windows task. I need to know when this information is recorded or not, maybe in an on-screen alert format, or something that catches your attention.

BS.: I know that there is an "r. out", but it overwrites, does not warn when the problem, or anything like that.

  • 1

    What exactly do you search for? Keep a log file? A popup message on your desktop screen? Send an email with warning? A text message? Whenever write or only when error occurs? All this is possible.

  • A pop-up on the screen would be perfect!

1 answer

1

Here’s how to generate a simple log file, which records the date and time and any possible error message:

logf <- file("exemplo.log", open = "a")
  writeLines(as.character(Sys.time()), logf)
  try(dbWriteTable(con, "tabela", tabela), outFile = logf)
close(logf)

If you need a more detailed record, see sink, which redirects the terminal output to a connection.

For error warning, you can use tryCatch and execute a system command. For example, to warn all users logged in to a *Nix server:

tryCatch(dbWriteTable(con, "tabela", tabela),
         error = system("wall 'Erro na gravação do DB'"))

For a message on the screen of your graphical environment, one option is the svDialogs package:

tryCatch(dbWriteTable(con, "tabela", tabela),
         error = svDialogs::msg_box("Erro na gravação do DB"))
  • I’ll test it! Thank you!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.