Explore Courses Blog Tutorials Interview Questions
0 votes
in R Programming by (50.2k points)

I want to read some .png files all one by one, and want to concatenate the text generated from all the files. I am using the below code:

filenames <- list.files(path = "C:/Users/tmpxk9/Documents", pattern="*.png")

for (i in seq_along(filenames)) {

  xx <- magick::image_read("filenames[i]")

  xx %>%

    magick::image_resize("2000x") %>%

    magick::image_convert(type = 'Grayscale') %>%

    tesseract::ocr() %>%



It errors out with the following error:

Error in magick_image_readpath(enc2native(path), density, depth, strip) : 

  rsession.exe: UnableToOpenBlob `C:\Users\tmpxk9\Documents\filenames[i]': No such file or directory @ error/blob.c/OpenBlob/2701

1 Answer

0 votes
by (108k points)

What I understand from your code is that you are trying to retrieve the file names, but they are not including the folder in which they are stored in. In order to get the full paths with list.files(), you have to add the argument :

full.names = TRUE

If you are a beginner and want to know more about R then do check out the R programming course that will help you in learning R from basics.

Related questions

Browse Categories