Some of my code which previously yielded a warning message is now giving an error. Here is an example:
library(sf)
states <- tigris::states(cb = T) %>% select(state = NAME) %>% filter(state == "Wisconsin")
wi.counties <- tigris::counties(state = "WI", cb = T) %>% select(county = NAME)
st_crs(states) == st_crs(wi.counties)
[1] TRUE
intersection <- st_intersection(states, wi.counties)
Error: (converted from warning) attribute variables are assumed to be spatially constant throughout all geometries
Previously, I just got the message "Warning: attribute variables are assumed . . ."
Now, the code entirely values due to the warning being converted to an error.
My question
Why is this warning now being converted to an error, and how can I make it stop doing that?
I'm running {{sf}} version 1.0.7 on R 4.2.0.
CodePudding user response:
It looks like you have somehow set your options
to convert all warnings to errors. To check whether this is the case, run getOption("warn")
. If so, the output will be 2
, or a value greater than 2 when converted to an integer:
If warn is negative all warnings are ignored. If warn is zero (the default) warnings are stored until the top–level function returns. If warn is one, warnings are printed as they occur. If warn is two (or larger, coercible to integer), all warnings are turned into errors.
Assuming that you know you can safely ignore the warning, you can reset it with:
options(warn=0)
See here for more info about the different options
settings.