In my code you can wrap the read.delim in a try() that will catch the error. You will still see the error in the console but the code will continue.
TxtFiles <- list.files(path = "FILES",pattern = "txt$")
MyFunc <- function(Nm) {
FullPath <- paste("FILES", Nm, sep="/")
DFname <- sub("\\.txt", "", Nm) #drop .txt from Nm
SUCCESS <- try(
DF <- read.delim(FullPath, header = TRUE, sep = "\t")
)
if(!inherits(SUCCESS, "try-error")) {
assign(DFname, DF, envir = .GlobalEnv)
}
}
library(purrr)
walk(TxtFiles, MyFunc)