I am attempting to write error messages for my script to a log file. It works when I do:
test <- file("error_file.log", open = "wt")
sink(test, type = "message")
try(data <- read.delim("genes2.txt",
header = TRUE,
as.is = TRUE))
sink(type = "message", append = TRUE)
close(test)
However, when I add an additional component to the script, it does not append both error messages. In this case both input files do not exist and should give a "no such file directory" for each file. Here is my attempt for both input files:
enter code heretest <- file("error_file.log", open = "wt")
sink(test, type = "message")
try(data <- read.delim("genes2.txt",
header = TRUE,
as.is = TRUE))
sink(type = "message", append = TRUE)
close(test)
test2 <- file("error_file.log", open = "wt")
sink(test2, type = "message")
try(variables <- read.delim("Book3.txt",
header = TRUE,
as.is = TRUE,
check.names = FALSE,
text = TRUE,
na.strings = c("", NA)))
sink(type = "message", append = TRUE)
close(test2)
Thank you!
P.s. would it be possible to customize my own error messages for each try()?