I am trying to log the errors and warnings of an R script into an external file. At the same time I want to be able to see the errors and warnings in the console in RStudio (useful to develop and debug). I am trying to use the following code:
logfile <- file("my_file_path", open="wt")
sink(logfile, type="message", split = TRUE)
But when I try to split the message connection using the funciton sink() I get the following error:
Error in sink(logfile, type = "message", split = TRUE) :
cannot split the message connection
Is there any workaround or alternative solution?
Thanks
file_con <- file("my_file_path", open = "a")
and then you dosink(logfile, type="message", split = TRUE)
. – Metalinguistics