Error in as.POSIXlt.character(x, tz, ...) : character string is not in a standard unambiguous format @spatialDetectionHistory

1,514 views
Skip to first unread message

Christu Raj

unread,
Jan 8, 2017, 8:15:47 AM1/8/17
to camtrapR
Dear group members,

I have the recordTableIndividual properly set with DateTimeOriginal in "%Y-%m-%d %H:%M:%S" format. Still when I run the spatialDetectionHistory function for generation of capthist object I get 'Error in as.POSIXlt.character(x, tz, ...) :    character string is not in a standard unambiguous format'.

I am not able to find the source of the problem. I checked the entire data and find no issues with the format of DateTimeOriginal. Any suggestions to solve this problem?

Regards
Christy

Juergen Niedballa

unread,
Jan 11, 2017, 8:41:08 AM1/11/17
to camtrapR
Dear Christy,
could you please show the output of str() of your recordTableIndividual?
Thanks
Jürgen

Ali Y

unread,
Feb 25, 2019, 4:21:44 PM2/25/19
to camtrapR
Hi Jurgen,

I am getting this error as well. I think I have improperly (or not at all) attempted to set my POSIXlt and POSIXct which may be a source of many of my errors regarding other code (???). Anyway, I am having this exact error when trying to run detectionHistory and would love any feedback you may have. 

>str(recordTable.all.df)
'data.frame': 2061 obs. of  30 variables:
 $ Camera_name          : Factor w/ 45 levels "C18","C19","C19_&_C27",..: 1 1 1 1 1 1 1 1 1 1 ...
 $ X.x                  : int  2015 1679 1680 1677 1887 2085 2002 1757 1681 2016 ...
 $ Species              : Factor w/ 32 levels "Chicken/roster",..: 14 14 14 14 23 14 23 27 14 14 ...
 $ DateTimeOriginal     : Factor w/ 1927 levels "1/10/17 19:57",..: 1901 1830 91 1901 93 1804 62 237 331 1830 ...
 $ Date                 : Factor w/ 346 levels "1/10/17","1/11/18",..: 341 324 33 341 34 320 28 59 81 324 ...
 $ Time                 : Factor w/ 2004 levels "0:01:27","0:02:08",..: 1577 1405 1282 1576 18 1403 1046 1140 1203 1406 ...
 $ delta.time.secs      : int  0 259267 2584370 83126 0 0 0 0 1811499 1189649 ...
 $ delta.time.mins      : int  0 4321 43073 1385 0 0 0 0 30192 19827 ...
 $ delta.time.hours     : num  0 72 717.9 23.1 0 ...
 $ delta.time.days      : num  0 3 29.9 1 0 0 0 0 21 13.8 ...
 $ Directory            : Factor w/ 65 levels "/Volumes/Untitled/Photos_original//2017-photos/C21",..: 40 40 40 40 40 40 40 40 40 40 ...
 $ FileName             : Factor w/ 1303 levels "01030049.JPG",..: 431 469 494 429 498 434 485 520 510 470 ...
 $ metadata_Number      : Factor w/ 10 levels ">5","1","1_&_2",..: 2 2 2 2 2 2 2 2 2 2 ...
 $ metadata_Group       : Factor w/ 12 levels "Bird","Bird_&_Mammal-IUCN EN or NT",..: 6 6 6 6 12 6 12 9 6 6 ...
 $ metadata_Species     : Factor w/ 38 levels "Chicken/roster",..: 16 16 16 16 26 16 26 31 16 16 ...
 $ metadata_Sex         : Factor w/ 4 levels "Female","Female_&_Male",..: NA NA NA NA NA NA NA NA NA NA ...
 $ metadata_Age_class   : Factor w/ 1 level "Juvenile": NA NA NA NA NA NA NA NA NA NA ...
 $ metadata_Activity    : Factor w/ 2 levels "Collecting","Hiking": NA NA NA NA NA NA NA NA NA NA ...
 $ metadata_Note        : Factor w/ 7 levels "Blur","Blur_&_Eye reflection",..: NA NA NA NA 2 NA 4 3 NA NA ...
 $ HierarchicalSubject.1: Factor w/ 2 levels "2017-photos",..: 2 2 2 2 2 2 2 2 2 2 ...
 $ HierarchicalSubject  : Factor w/ 750 levels "Activity|Collecting, Group|Human, Number|1, Sex|Male, Site ID|C70, SiteID|C70, Species|Other People",..: 613 331 331 331 557 740 598 427 331 613 ...

DateTimeOrginal (bolded) looks to me as it is in "%m/%d/%y %H:%M" format so my code for detection history is: 

>detectionDogs<-detectionHistory(recordTable =  recordTable.all.df[!is.na(recordTable.all.df$Species),],
                                species= "Domestic Dog",
                                camOp=camOp.df,
                                stationCol = "Plot_ID",
                                speciesCol = "Species",
                                day1= "station",
                                recordDateTimeCol = "DateTimeOriginal",
                                recordDateTimeFormat = "%m/%d/%y %H:%M",
                                occasionLength=1,
                                includeEffort = FALSE,
                                scaleEffort = FALSE,
                                occasionStartTime = 0,
                                datesAsOccasionNames = TRUE,
                                timeZone="UTC",
                                writecsv = TRUE,
                                outDir= outdir.dh)

but I get the error "Error in as.POSIXlt.character(x, tz, ...) : character string is not in a standard unambiguous format"

Does it matter that this is the structure of camOp (%Y-%m-%d)? 

>str(camOp.df)
'data.frame': 44 obs. of  1118 variables:
 $ 2015-01-21  : num  NA NA NA NA NA NA 1 NA NA NA ...
 $ 2015-01-22  : num  NA NA NA NA NA NA 1 NA NA NA ...
 $ 2015-01-23  : num  NA NA NA NA NA NA 1 NA NA NA ...
 $ 2015-01-24  : num  NA NA NA NA NA NA 1 NA NA NA ...
  [list output truncated]
 

Also, I noticed that my recordTable was in "%Y-%m-%d %H:%M:%S" format as a matrix, but when I converted it to a data.frame, the DateTimeOriginal column changed to "%m/%d/%y %H:%M". Is this a concern? I don't particularly need the seconds info. 

Thanks for any help!
Ali


Juergen Niedballa

unread,
Feb 26, 2019, 12:10:51 AM2/26/19
to camtrapR
Hi Ali,
the DateTimeOriginal column is a factor, not a date/time object. This means R doesn't know it is a date. It should be in POSIXct format. 

The seconds are lost probably because you opened the table in Excel and saved it there. You can get the original (including seconds) back in POSIXct format by running:

recordTable.all.df$DateTimeOriginal <- as.POSIXct(paste(recordTable.all.df$Date, recordTable.all.df$Time), tz = "UTC")

Set argument tz to whatever the correct time zone is, with UTC being a reasonable default even if your cameras were in a different time zone (because UTC does not have daylight saving time, see the vignette for more details). If your time zone has daylight saving time, use UTC. Otherwise, go ahead and use the correct time zone. See this thread for more information.

To avoid all character columns being converted to factors try loading the record table with read.csv(..., stringsAsFactors = FALSE).

It is hard to say whether the camera operation matrix is correct. If it is all NA, then clearly no. If there are cells with numbers, it should be fine.

Best,
Jürgen

Ali Y

unread,
Feb 26, 2019, 7:33:20 PM2/26/19
to camtrapR
Hi Jurgen,

Thank you for the help! I am still having the issue even after remaking the record table (and not opening it), running the script you provided, and loading the record table with stringsAsFactors=FALSE. I understand this might go beyond the purpose for this group, but I have limited R resources and I'm struggling to find the source of this problem, but, with your help, it seems I'm getting close!

The following are the classes of the date/time columns referenced in detectionHistory

> class(recordTable.all.df$Date)
[1] "Date"
> class(recordTable.all.df$Time)
[1] "factor"
> class(recordTable.all.df$DateTimeOriginal)
[1] "POSIXct" "POSIXt" 
> class(CTtable.df$Date_start)
[1] "POSIXct" "POSIXt" #make up colnames of camOp
> class(CTtable.df$Date_end)
[1] "POSIXct" "POSIXt" #make up colnames of camOp


I am using recordDateTimeCol = "DateTimeOriginal", recordDateTimeFormat = "%Y-%m-%d %H:%M:%S",  in the detectionHistory script and str(recordTable) at DateTimeOriginal now says "$ DateTimeOriginal     : POSIXct, format: "2017-10-17 21:00:20" "2017-09-17 23:07:32" "2017-09-17 23:07:31" "2017-11-12 02:22:28" ..." which seems like recordTable is now in POSIXct format and that I should use  "%Y-%m-%d %H:%M:%S" format. 

When I run the follow code I am still getting the same error:
detectionDogs<-detectionHistory(recordTable =  recordTable.all.df[!is.na(recordTable.all.df$Species),],
                                species= "Domestic Dog",
                                camOp=camOp.df,
                                stationCol = "Plot_ID",
                                speciesCol = "Species",
                                day1= "station",
                                recordDateTimeCol = "DateTimeOriginal",
                                recordDateTimeFormat = "%Y-%m-%d %H:%M:%S",
CameraOperationMatrix_by_station_2019-02-26.csv
recordTable.all.df.csv

Juergen Niedballa

unread,
Mar 3, 2019, 10:44:00 AM3/3/19
to camtrapR
Dear Ali,
all of this looks good so far and I tried running the code with the tables you provided. I get the following error:

Error: record date outside camera operation date range:  61

This only means that there is a mismatch between the camera operation time and the time of a record in station 61. I cannot reproduce the error.

Here is the code I used (where wd is the directory containing both tables):

camOp.df <- read.csv(file.path(wd, "CameraOperationMatrix_by_station_2019-02-26.csv"),
                  row.names = 1, check.names = FALSE)

recordTable.all.df <- read.csv(file.path(wd, "recordTable.all.df.csv"))


detectionDogs<-detectionHistory(recordTable =  recordTable.all.df[!is.na(recordTable.all.df$Species),],
                                species= "Domestic Dog",
                                camOp=camOp.df,
                                stationCol = "Plot_ID",
                                speciesCol = "Species",
                                day1= "station",
                                recordDateTimeCol = "DateTimeOriginal",
                                recordDateTimeFormat = "%Y-%m-%d %H:%M:%S",
                                occasionLength=1,
                                includeEffort = FALSE,
                                scaleEffort = FALSE,
                                occasionStartTime = 0,
                                datesAsOccasionNames = TRUE,
                                timeZone="UTC",
                                writecsv = F#,
                                #outDir= outdir.dh
                                )

ayo...@sdsu.edu

unread,
Mar 5, 2019, 5:20:56 PM3/5/19
to camtrapR
I had to do the following: 1)update my CTtable with correct date ranges 2) reformate my CTtable$Date_start and CTtable$Date_end with as.Dates 3)rerun camOp function. Then I wrote camOp and recordTable as CSVs and used the code you provided to load them back in and run detectionHistory with no errors.

Thank you so much for the help!

Jose Infante

unread,
Oct 26, 2020, 10:09:05 PM10/26/20
to camtrapR
Hi all,

I had the same problem and none of your suggestions worked for me. I don't know why but what did work was to change my time zone to an equivalent one, so in detectionHistory() I changed timeZone="Chile/Continental" for timeZone="Etc/GMT-3".  If anyone has an explanation for this I'd be happy to hear it!  

Best,

José.

Jürgen Niedballa

unread,
Oct 27, 2020, 6:33:42 AM10/27/20
to camt...@googlegroups.com

Hi José,

so your problem was in detectionHistory()? You got the Error message: Error in as.POSIXlt.character(x, tz, ...) when trying to run detectionHistory() and it was fixed by changing the timeZone argument?

That sounds odd. What version of camtrapR are you using?

Any chance you could share / email me the R workspace please? And the code you ran so I can try to reproduce the error?

Thank you,

Jürgen

--
You received this message because you are subscribed to a topic in the Google Groups "camtrapR" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/camtrapr/bxOL3xfN4G8/unsubscribe.
To unsubscribe from this group and all its topics, send an email to camtrapr+u...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/camtrapr/70cf8de5-7f98-4b6f-afe6-e4511d62ce49n%40googlegroups.com.

Jose Infante

unread,
Nov 9, 2020, 10:05:34 AM11/9/20
to camtrapR
Hi Juergen,

Yes, when using detectionHystory() it returned me this error: "Error in as.POSIXlt.character(x, tz, ...) : character string is not in a standard unambiguous format". It happened to a friend and he asked me to re run his code in my computer, I got his same error. After trying different things I could solve it the way I mentioned above. The camptrapR version I'm using is 1.2.3

I will e-mail you the workspace, code and data. 

Best,

José.

Juergen Niedballa

unread,
Nov 9, 2020, 10:39:44 AM11/9/20
to camtrapR
Hi José,
it seems that the date/time column is in a different format than expected. 

> head(Records.hobbit$DateTimeOriginal)
[1] "2019-05-30   5:49:19 PM"  "2019-06-16   5:10:55 AM" 

 whereas: 
recordDateTimeFormat = "%Y-%m-%d %H:%M:%S",
                                 
You will need to adapt recordDateTimeFormat to include the spaces and AM/PM indicator. 

I thought there would be a proper error message if  recordDateTimeFormat  is not correct, but apparently not. 
Also, your version is a bit old already. Newer versions of camtrapR usually have better error messages and useful bugfixes. 
Does this fix the problem?

Also, the new (development) version of the package complains that in two stations setup = retrieval: 
> stations[which(stations$Setup_date == stations$Retrieval_date),]
   Station utm_x utm_y Setup_date Retrieval_date
9    68109     0     0 2019-05-20     2019-05-20
50   68677     0     0 2019-05-27     2019-05-27

You may want to fix that also. 
Best regards,
Jürgen
Reply all
Reply to author
Forward
0 new messages