`Error in file(file, "rt") : invalid 'description' argument`

Hello,

currently I am working with RCNN and so I have been given a code of which I have to make some sense. I have 270 pictures which ran through a neural network and 270 .cvs-files on which the corresponding mask is noted on. Below is an extract of the code I'm working with:

library("imager")
library("OpenImageR")
library("stringr")
library("foreach")
library("openxlsx")

csvs <- list.files("C:\\Users\\ M N\\Bachelor\\RCNN_mushroom_test\\RCNN_mushroom_test\\customImages\\val2\\predict_results", full.names = T)

lITV <- list()
for(i in 1:270){
  
  print(i)
  mask <- read.csv2(csvs[i])
  im <- load.image(paste0("C:/Users/M N/Bachelor/imagos/Amanita_muscaria"
, str_extract_all(csvs[i], "\\d+")[[1]][2], ".jpg"))
                      
  im_hsl <- imager::RGBtoHSL(im)
  l <- im_hsl[,,,3]
  
  lITV[[i]] <- cbind.data.frame(lightness = c(l[mask == 0], l[mask == 1]), 
                            type = c(rep("background", length(l[mask == 0])), rep("mushroom", length(l[mask == 1]))),
                            ID = str_extract_all(csvs[i], "\\d+")[[1]][2])
  
  lITV[[i]] <- do.call(cbind, lapply(split(lITV[[i]], factor(lITV[[i]]$type)), function(x)  x[sample(nrow(x), 100), ]))
  lITV[[i]] <- lITV[[i]][, c(1, 3, 4)]
}

When I run it I get following error:

Error in file(file, "rt") : invalid 'description' argument

traceback() gives me following reports.

3: file(file, "rt")
2: read.table(file = file, header = header, sep = sep, quote = quote,
dec = dec, fill = fill, comment.char = comment.char, ...)
1: read.csv2(csvs[i])

I have looked up the error but didn't find any useful solutions. If further information is needed I'm more than happy to provide it. I'm fairly unexperienced with R, so please excuse if the answer was obvious.

Thanks in advance

What is the value of i when it stops? And the value of csvs[i]? My guess is you are trying to read in something that is not a csv (or not even a proper file). You can restrict to csv by using the pattern argument of list.files:

csvs <- list.files("C:\\Users\\ M N\\Bachelor\\RCNN_mushroom_test\\RCNN_mushroom_test\\customImages\\val2\\predict_results",
                   pattern = "*.csv", full.names = T)

Thank you for you answer. You're most likely right with your assumption. When i only run following lines, I get these error messages:

>   mask <- read.csv2(csvs[i])
Error in file(file, "rt") : invalid 'description' argument
>   im <- load.image(paste0(mani, str_extract_all(csvs[i], "\\d+")[[1]][2], ".jpg"))
Error in wrap.url(file, load.image.internal) : File not found

I'll look into it. Thanks again for leading me in the right direction.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.