Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

terra-dev breaks smoothr #15

Closed
rhijmans opened this issue Mar 5, 2023 · 1 comment
Closed

terra-dev breaks smoothr #15

rhijmans opened this issue Mar 5, 2023 · 1 comment

Comments

@rhijmans
Copy link

rhijmans commented Mar 5, 2023

The development version of "terra" breaks this chunk in the smootr vignette:

par(mar = c(0, 0, 0, 0), mfrow = c(1, 1))
# unwrap for use
data(jagged_raster)
jagged_raster <- rast(jagged_raster)

# pres/abs map
r <- classify(jagged_raster, rcl = c(-Inf, 0.5, Inf)) %>% 
  as.numeric()
plot(r, col = c("white", "#4DAF4A"), legend = FALSE, axes = FALSE)

# polygonize
r_poly <- as.polygons(r) %>% 
  st_as_sf() %>% 
  subset(value > 0)
plot(r_poly, col = NA, border = "grey20", lwd = 1.5, add = TRUE)

With messages

  --- re-building ‘smoothr.Rmd’ using rmarkdown
  Quitting from lines 252-267 (smoothr.Rmd)
  Error: processing vignette ‘smoothr.Rmd’ failed with diagnostics:
  object ‘value’ not found
  --- failed re-building ‘smoothr.Rmd’

The reason is that jagged_raster has layername "occurrence". This name was lost and became "value". That is no longer the case. So to make your code run you would need to do

r_poly <- as.polygons(r) %>% 
  st_as_sf() %>% 
  subset(occurrence > 0)

or this

r_poly <- ifel(r > 0, r, NA) |> 
  as.polygons() |> 
  st_as_sf() 

But since it seems to me that all values are larger than zero (either one or two); perhaps it should be > 1 instead of > 0
(that may be because of an earlier change in how classify creates categories.) That makes the example look better, I think. Either way, smootr looks like a very nice package!

I am trying to get this version to CRAN. If they accept it, you may get a report from them soon.

@mstrimas
Copy link
Owner

mstrimas commented Mar 7, 2023

Thanks for letting me know, I'll fix it this week and send the updated version to CRAN.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants