Error GetSpeciesImages Error: target directory is not empty

75 views
Skip to first unread message

Ana Barros

unread,
Nov 11, 2020, 10:23:33 AM11/11/20
to camtrapR
Hello, 

So I am really new to this package and frankly to R in general. I have a lot of camera-trap photos from several years (2013-2016). So I have 15 folders for each camera, for each folder I have another 4 folders with data for each year, and inside each year I have a couple more folders from each collected card.
I already tagged several photos and now I want to separate the photos for each species. I tried using a for loop so the getspeciesimages is applied to each year from one camera. However, when the first year is complete and it moves on to the next I get this error:
Error: target directory  E:\CameraTrap\Machine learning/Empty  is not empty

Basically, it created this folder Empty when it looked over the photos from the first year, but then when it moved to the next folder this error appeared and it stopped running.

The code is this:
for(i in 2013:2016){
getSpeciesImages(species = "Empty", inDir = file.path(paste("E:\\CameraTrap\\Fase1\\plot_1998-01\\", i, sep="")),
                 outDir = file.path("E:\\CameraTrap\\Machine learning"), createStationSubfolders = TRUE,
                 IDfrom="metadata", metadataSpeciesTag = "Species", metadataHierarchyDelimitor = "|")
}

What do I have to do? Thank you very much!!

Juergen Niedballa

unread,
Nov 16, 2020, 4:55:33 AM11/16/20
to camt...@googlegroups.com

Hi Ana,

yes, currently the function stops and throws an error if the target directory is not empty (contains images already). So in the first iteration of your loop it works (when the directory is still empty), in the second iteration it finds images and refuses to continue. 
The relevant code it quite old and I believe I added it to avoid accidentally overwriting images that were tagged already (thereby potentially losing the tags). And it also wasn't intended to contain subdirectories by year. The function is not very flexible to be honest.

So I'm sorry to say that in its current state, there is little the function can do out of the box. You could do one of these things:
  • change the directory structure
  • modify the getSpeciesImages function (the line that causes the error). 
Since you are new to R I did the latter for you. Please source the attached getSpeciesImages function. It is minimally modified and causes a warning instead of an error in your situation (line 52). Please use it carefully since it may overwrite existing images. I also don't know if the function would preserve the year directories you are using. Just try and see, but please make a backup first. 

Also run this line first, it loads a few functions that getSpeciesNames needs internally:

Hope this helps. And please let me know how it goes.
All the best,
Jürgen
--
You received this message because you are subscribed to the Google Groups "camtrapR" group.
To unsubscribe from this group and stop receiving emails from it, send an email to camtrapr+u...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/camtrapr/c09037b7-0eee-4e17-bed5-79c5ec5cbc68n%40googlegroups.com.
getSpeciesImages_for_Ana.R
Reply all
Reply to author
Forward
0 new messages