Good, I have a code in which by means of a loop they are opened and analyzed files that appear in a list. As I am going to have to analyze several files I want to print the name of the file that has problems to open. A problem that is common for files is missing a column name, for example instead of having:
ID; date; close; description
1;20-12-2017;0.5;"archivo"
has
ID; close; description
1;20-12-2017;0.5;"archivo"
This evidently raises an error since when reading the file it is seen that the number of column names does not correspond to the number of columns.
To detect these errors I am following the following code:
for (i in 1:length(files)){
tryCatch({
name<-as.character(files[i])
dat<-read.table(name,header = T,sep="@",dec=",",comment.char = "")
},
error<-function(e){
print("error in file",files[i])
})
where files is a list of files.
So what I'm trying to do is print the name of the file on the screen.
The error that jumps me is:
3.stop("bad handler specification")
2.tryCatch({
name <- as.character(files[i])
dat <- read.table(name, header = T, sep = "@", dec = ",",
comment.char = "") ...
1.data_function(files)
Thank you!