jmsigner / amt

37 stars 13 forks source link

`raster_to_terra()` fails for factors #87

Closed bsmity13 closed 1 year ago

bsmity13 commented 1 year ago

terra::rast() seems to fail when one RasterStack layer has factor levels (and the others do not?). I haven't looked into this thoroughly, but it might be a terra problem and not an amt problem. In the example below, the 4th layer of uhc_hab has factor levels while the others do not.

library(amt)

data(uhc_hab)

# Error:
amt:::raster_to_terra(uhc_hab)

# No error:
amt::raster_to_terra(stack(uhc_hab[[1]], uhc_hab[[2]]))

# Error:
amt::raster_to_terra(stack(uhc_hab[[1]], uhc_hab[[4]]))

Seems like an easy fix by creating uhc_hab with terra in the first place. I'm working on that now. Thought this was worth documenting here in case we see it again in the future.

bsmity13 commented 1 year ago

Closed.