jmsigner / amt

37 stars 13 forks source link

Should objects of class `random_points` also inherit from `track_xy`? #102

Closed bsmity13 closed 6 months ago

bsmity13 commented 7 months ago

I came across a case where a user would rather reproject the points to match the CRS of a raster, rather than reprojecting a raster to match the CRS of the points.

I thought transform_coords() would work, but there is no S3 method for object of class random_points. Example:

library(amt)
library(dplyr)

amt_fisher %>% 
  filter(name == "Leroy") %>% 
  random_points() %>% 
  transform_coords(32607) # error

In trying to coerce the object, I also found that the object of class random_points doesn't inherit the attributes from the track_xy*, for example, the CRS.

One solution would be to write transform_coords.random_points(), but I suspect that it might be more consistent to just set the class of the object returned by random_points() to c("random_points", "track_xy", "tbl_df", "tbl", "data.frame") and transfer the attributes (maybe just the CRS) from the track_xy* to the new object. This is consistent with random_steps() returning an object of class c("random_steps", "steps_xyt", "steps_xy", "tbl_df", "tbl", "data.frame").

Are there any downsides to this I'm not seeing?

jmsigner commented 6 months ago

Good point, I added this a1308d5 and will submit to CRAN soon.