Closed tmeeha closed 3 months ago
Hi, can you provide some more information, i.e. sessionInfo()
and the full error messages you get with the original code. I don't get any errors with the current code, and looking at the data contents before the rename(count = sum)
line, the data.frame does contain a variable called sum
(which isn't ideal, but does seem to work as intended). I'm not sure where your lyr1
variable is meant to come from?
Similarly for the second part; I don't see a problem on my end, and based on the contents of the data, the vegetation variable does need to be extracted:
> gcov_lvls[[1]]
value vegetation
1 1 Colonising
2 2 Disturbed
3 3 Grassland
4 4 Primary
5 5 Secondary
6 6 Transition
I have the latest terra
version, 1.7-71. I wonder if you might have an outdated terra version, as both inlabru and terra were updated recently (December/January) to fix a previous terra interface issue and its interaction with how inlabru needed to use it. Not sure if that particular issue is involved here, but it's the best guess I have.
I did not have the latest versions of terra or inlabru. Now that I have updated it works fine. Sorry for the diversion. Here are the old errors in case this is helpful:
counts_df <- crds(counts_rstr, df = TRUE, na.rm = TRUE) %>%
- bind_cols(values(counts_rstr, mat = TRUE, na.rm = TRUE)) %>%
- rename(count = sum) %>%
- mutate(present = count > 0) %>%
st_as_sf(coords = c("x", "y"), crs = st_crs(nests)) Error in
rename()
: ! Can't rename columns that don't exist. ✖ Columnsum
doesn't exist. Runrlang::last_trace()
to see where the error occurred. rlang::last_trace() <error/vctrs_error_subscript_oob> Error inrename()
: ! Can't rename columns that don't exist. ✖ Columnsum
doesn't exist.Backtrace: ▆
- ├─... %>% st_as_sf(coords = c("x", "y"), crs = st_crs(nests))
- ├─sf::st_as_sf(., coords = c("x", "y"), crs = st_crs(nests))
- ├─dplyr::mutate(., present = count > 0)
- ├─dplyr::rename(., count = sum)
- └─dplyr:::rename.data.frame(., count = sum) Run rlang::last_trace(drop = FALSE) to see 19 hidden frames. Warning message: In class(object) <- "environment" : Setting class(x) to "environment" sets attribute to NULL; result will no longer be an S4 object
names(gcov_vegetation) <- gcov_lvls[[1]]$vegetation Error in gcov_lvls[[1]]$vegetation : $ operator is invalid for atomic vectors
Thanks!
I found a few minor bugs in the ZIP/ZAP vignette. Here are the fixes.