spluque / diveMove

diveMove is a GNU R package with tools to represent, visualize, filter, analyse, and summarize time-depth recorder (TDR) data. It also provides miscellaneous functions for handling location data.
6 stars 2 forks source link

Error in diveStats when there are no dives #1

Closed mczapanskiy-usgs closed 8 years ago

mczapanskiy-usgs commented 9 years ago

If you run diveStats on a tdr that doesn't have any dives you get the following error: Error in do.call(rbind, by(td, dids, oneDiveStats, interval = interval)) : second argument must be a list

[Note: traceback doesn't provide a useful stack]

This code reproduces the error:

library('diveMove')
raw <- data.frame(time = seq(as.POSIXct('2015-09-25 09:00:01', tz = 'UTC'), 
                             as.POSIXct('2015-09-25 09:00:10', tz = 'UTC'), 
                             by = 'sec'), 
                  depth = 0)
tdr <- createTDR(raw$time, 
                 raw$depth, 
                 dtime = 1,
                 file = 'none')
calib <- calibrateDepth(tdr, 
                        wet.thr = .5, 
                        dive.thr = .5,
                        zoc.method = 'offset', 
                        offset = 0)
diveStats(calib)

This may seem like an esoteric error, but it becomes important when analyzing tags that record pressure in bursts. For example, CEFAS tags can be programmed to take .1s readings only when the tag is wet. It's impossible (I think) to use diveMove to analyze the entire data set when the records are in scattered pulses. Instead, it's easier to treat each burst as a separate unit for analysis. A non-trivial number of these records will have no dives in them.

I'm using try-catch as a workaround, but this seems like a bug worth fixing internally. Thanks for your good work - diveMove is a fantastic package!

spluque commented 9 years ago

On Fri, 25 Sep 2015 10:05:38 -0700, Max Czapanskiy notifications@github.com wrote:

If you run diveStats on a tdr that doesn't have any dives you get the following error: Error in do.call(rbind, by(td, dids, oneDiveStats, interval = interval)) : second argument must be a list

Thanks for the report. What version are you using? Please include your sessionInfo(). Here's mine:

R> sessionInfo() R version 3.2.2 (2015-08-14) Platform: x86_64-pc-linux-gnu (64-bit) Running under: Debian GNU/Linux stretch/sid

locale: [1] LC_CTYPE=en_CA.UTF-8 LC_NUMERIC=C LC_TIME=en_CA.UTF-8 LC_COLLATE=en_CA.UTF-8 LC_MONETARY=en_CA.UTF-8 LC_MESSAGES=en_CA.UTF-8
[7] LC_PAPER=en_CA.UTF-8 LC_NAME=C LC_ADDRESS=C LC_TELEPHONE=C LC_MEASUREMENT=en_CA.UTF-8 LC_IDENTIFICATION=C

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

other attached packages: [1] diveMove_1.4.0 slmisc_1.2 latticeExtra_0.6-26 RColorBrewer_1.1-2 lattice_0.20-33

loaded via a namespace (and not attached): [1] bitops_1.0-6 grid_3.2.2 MatrixModels_0.4-1 KernSmooth_2.23-15 geosphere_1.4-3 SparseM_1.7 sp_1.2-0 Matrix_1.2-2 tools_3.2.2
[10] compiler_3.2.2 caTools_1.17.1 quantreg_5.19

And your code gives me:

R> calib <- calibrateDepth(tdr,

Seb

spluque commented 8 years ago

Closing this, as I cannot reproduce it with the info provided after 6 months. Feel free to re-open if it still persists and can provide more info.