2

I want to load more than one image with load.image() function provided in "imager" package, but i have got an Error with "File not found" message. Could someone please help me in this problem?

I've tried to load the images in the list, and add this list as a parameter to the load.image() function, but it can only read one file, so the list is not acceptable. After this i tried to iterate in the list with a for loop, and add the index from the loop as the parameter, and i've got this problem: "Error in wrap.url(file, load.image.internal) : File not found"

filenames <- list.files("~/Downloads/project", pattern="*.JPG")

for(idx in filenames) {
   load.image(idx)
   "I tried here with concatenate the idx with the path string, but with no success"
   load.image(paste("~/Downloads/project",idx))  
}
  • It might be as simple as specifying the seperator you want to use in your paste function. load.image(paste("~/Downloads/project",idx,sep="")) – olorcain Apr 06 '19 at 12:17

1 Answers1

2

Try adding full.names = T option to the list.files. This adds the full path to the file, if not present only the file name is returned.

list.files("~/Downloads/project", pattern="*.JPG", full.names = T)

then just load.image(idx) in your loop

R. Schifini
  • 9,085
  • 2
  • 26
  • 32
  • Hello again! Could you please help me with another problem too? Loading more files with load.image() function runs successfully now, but i've got the following problem. When i want to add this "idx" parameter to a function called grayscale() i've got the following error: "Error in if (spectrum(im) == 1) { : argument is of length zero" Could you please give me any hint, what cause this exactly? Thank you in advance! – Bálint Molnár Apr 07 '19 at 20:07
  • @BálintMolnár I'd suggest you open a new question with your code and some sample data that could reproduce the error you have. I'm assuming that you have searched the error message and the function that triggers it, and that you haven't found a satisfactory answer. – R. Schifini Apr 08 '19 at 01:51
  • Hello @R. Schifini. I've opened a new question for it: https://stackoverflow.com/questions/55580110/list-element-set-as-parameter-to-grayscale-function-leads-to-error I've tried to run only the code part, what you can see in this link, with the necessary packages in the beggining, like: require(imager); but i've got the same error, so i could debug it, because i got this error only when i want to run the grayscale() function. The datas \ pictures what i use just are simply jpg files from traffic sights. Could you please have a look at the question from the link in my comment? Thank you! – Bálint Molnár Apr 08 '19 at 19:03