cameraOperation() in v 2.0.2 works but v 2.0.3 fails

162 views
Skip to first unread message

davidgeorg...@gmail.com

unread,
Mar 23, 2021, 9:58:04 PM3/23/21
to camtrapR
Jürgen

When I run cameraOperation() in v 2.0.2 it works but in v 2.0.3  it fails.

Boral.op <- cameraOperation(CTtable = Boral.stns,
                                 stationCol   = "Station",
                                 setupCol     = "DateDeployed",
                                 retrievalCol = "DateRetrieved",
                                 writecsv     = FALSE,
                                 sessionCol   = "session",
                                 hasProblems  = TRUE)

The error is

Error in charToDate(x) : character string is not in a standard unambiguous format


Traceback reports

7.  stop("character string is not in a standard unambiguous format")
6. charToDate(x)
5. as.Date.character(e2)
4. as.Date(e2)
3. `==.Date`(inputColumn, "")
2. parseDateObject(inputColumn = CTtable[, problemFromColumn], dateFormat, checkNA = FALSE, checkEmpty = FALSE)
1. cameraOperation(CTtable = Boral.stns, stationCol = "Station", setupCol = "DateDeployed", retrievalCol = "DateRetrieved", writecsv = FALSE, sessionCol = "session", hasProblems = TRUE)

We also noticed that if the hasProblems = FALSE it runs - but my data does have a problem.

If I look at the relevant dates they are correct.
Boral.stns[, 6:9]
   DateDeployed DateRetrieved Problem1_from Problem1_to
1    2020-08-27    2020-10-28          <NA>        <NA>
2    2020-10-28    2020-12-23          <NA>        <NA>
3    2020-08-27    2020-10-28          <NA>        <NA>
4    2020-10-28    2020-12-23          <NA>        <NA>
5    2020-08-27    2020-10-28          <NA>        <NA>
6    2020-10-28    2020-12-23          <NA>        <NA>
7    2020-08-27    2020-10-28    2020-09-14  2020-10-28
8    2020-10-28    2020-12-23          <NA>        <NA>
9    2020-08-27    2020-10-28          <NA>        <NA>
10   2020-10-28    2020-12-23          <NA>        <NA>

In my preferred format they were Date-times, but I changed them to as.Date() to see if they helped - but no.  

I have run the code  number of times. The Trace Back reports are not identical. An early run talked about POSIXlt and ct. Why?  I went to a lot of trouble to ensure they are all POSIXct, all in in the same time zone (UTC+10).

Regards
David


Juergen Niedballa

unread,
Mar 25, 2021, 5:51:28 AM3/25/21
to camtrapR
Hi David, 
can you please try with the github version? It should hopefully fix the date issues in 2.0.3

library(remotes)
install_github("jniedballa/camtrapR")

Thank you,
Jürgen

davidgeorg...@gmail.com

unread,
Mar 25, 2021, 3:55:56 PM3/25/21
to camtrapR
No joy, Jürgen

When asked for the additional packages, I selected all, 1.


Here is the console output.  Interestingly there is no traceback.

> Boral.op <- cameraOperation(CTtable = Boral.stns,
+                             stationCol   = "Station",
+                             setupCol     = "DateDeployed",
+                             retrievalCol = "DateRetrieved",
+                             writecsv     = FALSE,
+                             sessionCol   = "session",
+                             hasProblems  = FALSE,
+                             dateFormat   = "%Y-%m-%d")
Error in cameraOperation(CTtable = Boral.stns, stationCol = "Station",  : 
  could not find function "cameraOperation"
> Boral.op <- cameraOperation(CTtable = Boral.stns,
+                             stationCol   = "Station",
+                             setupCol     = "DateDeployed",
+                             retrievalCol = "DateRetrieved",
+                             writecsv     = FALSE,
+                             sessionCol   = "session",
+                             hasProblems  = TRUE,
+                             dateFormat   = "%Y-%m-%d")
Error in cameraOperation(CTtable = Boral.stns, stationCol = "Station",  : 
  could not find function "cameraOperation"

Also - if relevant.
> sessionInfo()
R version 4.0.2 (2020-06-22)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS  10.16

Matrix products: default
LAPACK: /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRlapack.dylib

locale:
[1] en_AU.UTF-8/en_AU.UTF-8/en_AU.UTF-8/C/en_AU.UTF-8/en_AU.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] remotes_2.2.0    bookdown_0.20    knitr_1.29       lubridate_1.7.10 ggplot2_3.3.2   
[6] SOAR_0.99-11    

loaded via a namespace (and not attached):
 [1] tidyselect_1.1.0  xfun_0.16         purrr_0.3.4       splines_4.0.2     lattice_0.20-41  
 [6] colorspace_1.4-1  vctrs_0.3.2       generics_0.1.0    htmltools_0.5.0   AICcmodavg_2.3-1 
[11] stats4_4.0.2      yaml_2.2.1        pkgbuild_1.1.0    survival_3.2-3    rlang_0.4.10     
[16] pillar_1.4.6      glue_1.4.2        withr_2.4.1       sp_1.4-5          lifecycle_0.2.0  
[21] plyr_1.8.6        munsell_0.5.0     gtable_0.3.0      raster_3.4-5      codetools_0.2-16 
[26] VGAM_1.1-5        evaluate_0.14     callr_3.4.3       ps_1.3.3          parallel_4.0.2   
[31] curl_4.3          fansi_0.4.1       highr_0.8         Rcpp_1.0.6        xtable_1.8-4     
[36] backports_1.1.8   scales_1.1.1      unmarked_1.0.1    digest_0.6.25     processx_3.4.3   
[41] dplyr_1.0.2       rprojroot_1.3-2   grid_4.0.2        cli_2.0.2         tools_4.0.2      
[46] magrittr_2.0.1    tibble_3.0.3      crayon_1.3.4      pkgconfig_2.0.3   MASS_7.3-51.6    
[51] ellipsis_0.3.1    Matrix_1.2-18     prettyunits_1.1.1 assertthat_0.2.1  rmarkdown_2.5    
[56] rstudioapi_0.11   R6_2.4.1          nlme_3.1-148      compiler_4.0.2   

davidgeorg...@gmail.com

unread,
Mar 25, 2021, 6:52:54 PM3/25/21
to camtrapR
Jürgen

Success.   I am sorry - your 
library(remotes)
install_github("jniedballa/camtrapR")
does indeed work. 

I failed to add the library(camtrapR) call after the install_github().
I made the same mistake when I tried to revert to camtrapR 2.0.2, so that explains why I could not reproduce my colleague's success with 2.0.2.
I did see the error message "cannot find the function cameraOperation" and while I found that strange, I did not realise camtrapR had not loaded. It needed my colleague to explain that to me.

David

davidgeorg...@gmail.com

unread,
Mar 26, 2021, 6:48:21 PM3/26/21
to camtrapR
Jürgen

I call
> Boral.stns[, c(1, 6:9, 18)]
      Station        DateDeployed       DateRetrieved       Problem1_from         Problem1_to session
1  WGND_BlPk1 2020-08-27 10:00:10 2020-10-28 10:00:00                <NA>                <NA>  202010
2  WGND_BlPk1 2020-10-28 10:00:00 2020-12-24 08:54:10                <NA>                <NA>  202012
3  WGND_BlPk2 2020-08-27 10:00:10 2020-10-28 10:00:00                <NA>                <NA>  202010
4  WGND_BlPk2 2020-10-28 10:00:00 2020-12-24 08:56:00                <NA>                <NA>  202012
5  WGND_BlPk3 2020-08-27 10:00:10 2020-10-28 10:00:00                <NA>                <NA>  202010
6  WGND_BlPk3 2020-10-28 10:00:00 2020-12-24 09:07:00                <NA>                <NA>  202012
7  WGND_BlPk4 2020-08-27 10:00:10 2020-10-28 10:00:00 2020-09-14 15:30:00 2020-10-28 10:00:00  202010
8  WGND_BlPk4 2020-10-28 10:00:00 2020-12-24 09:15:00                <NA>                <NA>  202012
9  WGND_BlPk5 2020-08-27 10:00:10 2020-10-28 10:00:00                <NA>                <NA>  202010
10 WGND_BlPk5 2020-10-28 10:00:00 2020-12-24 09:25:00                <NA>                <NA>  202012
> Boral.op <- cameraOperation(CTtable = Boral.stns,
+                             stationCol   = "Station",
+                             setupCol     = "DateDeployed",
+                             retrievalCol = "DateRetrieved",
+                             writecsv     = FALSE,
+                             sessionCol   = "session",
+                             hasProblems  = TRUE,
+                             dateFormat   = "%Y-%m-%d") 
Warning messages:
1: There are spaces in CTtable[, setupCol], but not in dateFormat 
2: There are spaces in CTtable[, retrievalCol], but not in dateFormat 
3: There are spaces in CTtable[, problemFromColumn], but not in dateFormat 
4: There are spaces in CTtable[, problemToColumn], but not in dateFormat 
> #   %H:%M:%S"

I cannot get rid of the warnings.  To fix this, I added what I believe is the correct date format  ("%Y-%m-%d %H:%M:%S") and I got an error "rows 4, 6, 8, 10 are identical" or similar depending on whether I use %H:%M:%S  or %H:%M or %H in the date format argument. There is only one space between "d" and  "%H..."

David

Juergen Niedballa

unread,
Mar 29, 2021, 11:43:01 AM3/29/21
to camtrapR
Hi David,
regarding the date format, the first camera was deployed "2020-08-27 10:00:10". So that doesn't match dateFormat = "%Y-%m-%d". So what you wrote should work: "%Y-%m-%d %H:%M:%S". Alternatively you may want to try the lubridate data format, it's usually easier that way. In your case it should be dateFormat = "ymd HMS".
Not entirely sure about the warnings you had, but you may need to format "session" as a sequence of numbers starting with 1. I think that was due to the expected data format for secr, and me then tailoring the functions to adhere to that. Feel free to share the exact warnings and I'll have a look.
Best,
Jürgen

davidgeorg...@gmail.com

unread,
Apr 3, 2021, 8:43:48 PM4/3/21
to camtrapR
Jürgen

I have a version of my script to run but there are things that are not right.

library(remotes)
install_github("jniedballa/camtrapR")
library(camtrapR)
sessionInfo()
camtrapR_2.1.0


# My ‘camtraps’ Stations file

> Boral.stns[, c(1, 6:9, 18)]
      Station        DateDeployed       DateRetrieved       Problem1_from         Problem1_to session
1  WGND_BlPk1 2020-08-27 10:00:10 2020-10-28 13:00:00                <NA>                <NA>  202010
2  WGND_BlPk1 2020-10-28 13:00:00 2020-12-24 08:54:10                <NA>                <NA>  202012
3  WGND_BlPk2 2020-08-27 10:00:10 2020-10-28 13:07:00                <NA>                <NA>  202010
4  WGND_BlPk2 2020-10-28 13:07:00 2020-12-24 08:56:00                <NA>                <NA>  202012
5  WGND_BlPk3 2020-08-27 10:00:10 2020-10-28 13:15:00                <NA>                <NA>  202010
6  WGND_BlPk3 2020-10-28 13:15:00 2020-12-24 09:07:00                <NA>                <NA>  202012
7  WGND_BlPk4 2020-08-27 10:00:10 2020-10-28 13:20:00 2020-09-14 15:30:00 2020-10-28 13:20:00  202010
8  WGND_BlPk4 2020-10-28 13:20:00 2020-12-24 09:15:00                <NA>                <NA>  202012
9  WGND_BlPk5 2020-08-27 10:00:10 2020-10-28 13:25:00                <NA>                <NA>  202010
10 WGND_BlPk5 2020-10-28 13:25:00 2020-12-24 09:25:00                <NA>                <NA>  202012

Boral.op <- cameraOperation(CTtable = Boral.stns,
                            stationCol   = "Station",
                            setupCol     = "DateDeployed",
                            retrievalCol = "DateRetrieved",
                            writecsv     = FALSE,
                            sessionCol   = "session",
                            hasProblems  = TRUE,
                            dateFormat   = "%Y-%m-%d”) 
There are spaces in CTtable[, setupCol], but not in dateFormatThere are spaces in CTtable[, retrievalCol], but not in dateFormatThere are spaces in CTtable[, problemFromColumn], but not in dateFormatThere are spaces in CTtable[, problemToColumn], but not in dateFormat


# first row first few columns
> head(Boral.op[ , 1:5], 1)
                        2020-08-27 2020-08-28 2020-08-29 2020-08-30 2020-08-31
WGND_BlPk1__SESS_202010        0.5          1          1          1          1
# correct.  BUT, the dateFormat is not correct
# the 0.5 comes from the correct calculation that the first day the camera was deployed, it was only deployed for 11 hours, ~0.5 days.

# change the last argument to cameraOperation() to the correct dateFormat
> Boral.op <- cameraOperation(CTtable = Boral.stns,
+                             stationCol   = "Station",
+                             setupCol     = "DateDeployed",
+                             retrievalCol = "DateRetrieved",
+                             writecsv     = FALSE,
+                             sessionCol   = "session",
+                             hasProblems  = TRUE,
+                             dateFormat   = "%Y-%m-%d %H:%M:%S") 
provided 9 variables to replace 1 variablesprovided 9 variables to replace 1 variablesError: row 4, 6, 8, 10: setup is identical to retrieval
# not what we would expect


#. if I do not include the last argument, it runs and gives the correct answer.

Thanks for your help.
David

Juergen Niedballa

unread,
Apr 5, 2021, 12:14:09 PM4/5/21
to camtrapR
Hi David, 

The first warning is correct (about the missing spaces), just not formatted nicely. It think the function returns output because it interprets the columns as dates (not date-time). This is because first part of your date/time strings can be interpreted as dates according to your dateFormat, and then the hours get truncated. When provided with dates only (no time), the function assumes 12 noon for setup because no exact time information is know. Hence the function output is exactly 0.5 on the first day. If the function really understood it to be 11 am, it should be around 0.54 (13 out of 24 hours active). 

The second problem is probably because there are duplicates in the station column. That means the function doesn't understand your session column. Something is going wrong there.

Would you mind sending me a your workspace please (feel free to restrict it to a few rows, just enough to reproduce the problem). Can email if you want. I'll then check what the issue is and fix it.

Thank you,
Jürgen
Reply all
Reply to author
Forward
0 new messages