jniedballa / camtrapR

R package for camera trap data management
https://jniedballa.github.io/camtrapR/
31 stars 5 forks source link

detectionHistory: occasion = 0 possible when recordDateTime is date only #5

Closed jniedballa closed 4 years ago

jniedballa commented 4 years ago

e.g. detectionHistory(..., recordDateTimeCol ="Date", recordDateTimeFormat = "dmy", day1 = "station" or "2015-12-01")

Seems to occur with output = "count" only.

When there is a record on the day the camera was set up and record times are dates without time, difftime between setup date and record date is 0. (detHist: # calculate the occasion each record belongs into from the time difference between records and beginning of the first occasion)

Then detHist: # fill detection matrix with 1 (or count) in appropriate cells can't access column 0, causing this error:

"Error in record.hist[match(names(occasions.by.station)[xyz], rownames(record.hist)),  : 
  number of items to replace is not a multiple of replacement length"

Possible solutions:

  1. Force users to provide time for dates (at least check + warn)
  2. if no time provided, assign 12 noon or something to allow difftime calculations (not midnight, then difference may be 0 again).
courtiol commented 4 years ago

IMO the best approach would be the 1. with a stop() call. The error message would explain the issue and suggested call that users can run to solve it. The suggested call would rely on a (new) camtrapR function implementing 2. The new function would contain an argument for the time the user wants to make up with perhaps no default.

That way the user will clearly realize the possible consequences of her action.

jniedballa commented 4 years ago

Thank you. I started working on it already and the issue should be resolved with today's commit. I went with option 2, which should make the function more useful for anyone who doesn't have time of day information, with a clear warning about what the function does (assign occasionStartTime + 1 second). It doesn't really matter what time it assigns, since temporal resolution is 1 day maximum and it cannot spill over into the next day (occasionStartTime can only be 0...23). Also, this is done only if not a single record has time information. If after assinging the time there's still occasions 0, there's a stop() to catch it. So far it is a pretty rare scenario anyways.