b-steve / acre

Acoustic spatial capture-recapture models
GNU General Public License v3.0
3 stars 1 forks source link

Do something different when the traps argument of `read.acre()` does not have column names #21

Open b-steve opened 5 months ago

b-steve commented 5 months ago

The traps argument provided to read.acre() needs to have columns named x and y. At the moment, if you forget to name your columns, then read.capt() executes without error, but functions applied to the resulting object (e.g., plot(data, type = "capt")) do result in errors and it's not obvious to the user what their mistake was.

Some possible solutions:

  1. Get read.acre() to throw an informative error when the columns in traps are not named x and y.
  2. Get read.acre() to name the columns x and y if they are not named.

The latter is easier for the user, but the former would assume the first column provides the x-coordinate and the second column provides the y-coordinate, which might be risky.

JosephReps commented 1 month ago

I've implemented it so:

If any change is required, warning is output:

Warning message:
In FUN(X[[i]], ...) :
  'traps' object missing required column names 'x' and 'y'. Columns will be renamed.

(Not really sure about this message, maybe you could think of a better warning?)

Works for list of traps, for example when multiple session data is present. Also works for NULL trap names. (Anymore edge cases?)

Sidenote: Found out is.list(data.frame()) returns TRUE??? But is(data.frame(), 'list') returns false... WHYY :(

Additional sidenote: I've added the check in read.acre() rather than create.capt() as I felt it was more appropriate here, maybe you have different opinion.

b-steve commented 1 month ago

Thanks! Let's add the check that the traps object has two columns. For the warning message, how about this?

"The traps object is missing the column names x and y. The first and second columns are being treated as the x- and y-coordinates, respectively".