Skip to content

Commit a75930e

Browse files
authored
Update digestR.R
1 parent 0966dcf commit a75930e

File tree

1 file changed

+24
-19
lines changed

1 file changed

+24
-19
lines changed

R/digestR.R

+24-19
Original file line numberDiff line numberDiff line change
@@ -6498,28 +6498,34 @@ pseudo1D <- function(x){range(x)[which.max(abs(range(x)))]}
64986498
# return(invisible(usrList))
64996499
# }
65006500
#######################################################################################
6501-
handleFoErrors <- function(cond, fileName = NULL) {
6501+
handleFoErrors <- function(cond, fileName = NULL, logFile = "fo_error_log.txt") {
65026502
# Set errors flag to TRUE to indicate that an error occurred
65036503
errors <<- TRUE
65046504

6505+
# Get the current timestamp
6506+
timestamp <- Sys.time()
6507+
65056508
# Customize the error message based on the error type or condition
6506-
if (grepl("unused argument \\(cond\\)", cond$message)) {
6507-
log_message <- "An unused argument error occurred in the function. Please check the function arguments."
6508-
} else if (grepl("truncating string with embedded nuls", cond$message)) {
6509-
# Specific handling for "truncating string with embedded nuls" warnings/errors
6510-
log_message <- paste("Warning: A truncation error occurred due to embedded null characters in the file:",
6511-
if (!is.null(fileName)) basename(fileName) else "", sep = " ")
6509+
if (grepl("truncating string with embedded nuls", cond$message)) {
6510+
# Suppress "truncating string with embedded nuls" warnings
6511+
log_message <- paste0("[", timestamp, "] Warning: A truncation issue occurred due to embedded null characters in the file: ",
6512+
if (!is.null(fileName)) basename(fileName) else "")
6513+
# Return NULL but suppress further output for these specific warnings
6514+
return(NULL)
6515+
} else if (grepl("unused argument \\(cond\\)", cond$message)) {
6516+
log_message <- paste0("[", timestamp, "] An unused argument error occurred. Please check the function arguments.")
65126517
} else {
65136518
# Generic error handling for other types of errors
6514-
log_message <- paste("An error occurred while processing", if (!is.null(fileName)) basename(fileName) else "", ":", cond$message)
6519+
log_message <- paste0("[", timestamp, "] An error occurred while processing ",
6520+
if (!is.null(fileName)) basename(fileName) else "", ": ", cond$message)
65156521
}
6516-
6517-
# Log the error message to a log file or suppress the output
6518-
write(log_message, file = "fo_error_log.txt", append = TRUE)
6519-
6522+
6523+
# Log the error message to the log file
6524+
write(log_message, file = logFile, append = TRUE)
6525+
65206526
# Optionally print the message for debugging purposes (comment out to suppress completely)
65216527
cat(log_message, "\n")
6522-
6528+
65236529
# Return NULL or an appropriate value to allow the function to continue
65246530
return(NULL)
65256531
}
@@ -6635,7 +6641,7 @@ file_open <- function(fileName, ...){
66356641
}
66366642

66376643
## Tell user which files have been loaded
6638-
log_message(basename(usrList[i]), quote = FALSE)
6644+
#log_message(basename(usrList[i]), quote = FALSE)
66396645
flush.console()
66406646
}
66416647

@@ -6644,8 +6650,7 @@ file_open <- function(fileName, ...){
66446650
myAssign("currentSpectrum", currentSpectrum, save.backup = FALSE)
66456651

66466652
## Refresh the splash screen after the files are loaded and currentSpectrum is set
6647-
if (!is.null(fileFolder) && length(fileFolder) > 0) {
6648-
log_message("Refreshing splash screen with current spectrum.")
6653+
if (!is.null(fileFolder) && length(fileFolder) > 0) {
66496654

66506655
## Ensure the graphical device is ready and refresh splash screen
66516656
if (dev.cur() == 1) {
@@ -6655,13 +6660,13 @@ file_open <- function(fileName, ...){
66556660
splashScreen() # Call the splash screen
66566661

66576662
## Short delay to ensure screen is ready
6658-
Sys.sleep(0.5)
6663+
#Sys.sleep(0.5)
66596664

66606665
## Force a redraw of the graphics device
66616666
dev.flush()
66626667
refresh(...)
6663-
}
6664-
6668+
}
6669+
66656670
## Display error dialog if errors occurred
66666671
if (errors) {
66676672
myMsg(paste('Errors occurred while opening files. Check the R console for details.', sep = '\n'), icon = 'error')

0 commit comments

Comments
 (0)