#StackBounty: #r #function #dplyr mutate cannot find function

Bounty: 100

I’m working through eBird code from this webpage:

with the exception of using my own data. I have a .gpkg from gadm.org of Australia, and my own ebird data selected for Australia. I have followed out the code exactly with the exception of not using "bcr" as my dataset has no bcr codes, along with removing st_buffer(dist = 10000) from the rgdal code because this prevented me from actually downloading the MODIS data for some reason.

EDIT:I have also used the provided data from the site and still received the same error

I got stuck at this code:

lc_extract <- ebird_buff %>% 
mutate(pland = map2(year_lc, data, calculate_pland, lc = landcover)) %>% 
select(pland) %>% 
unnest(cols = pland)

It returns this error:

Error: Problem with `mutate()` input `pland`.
x error in evaluating the argument 'x' in selecting a method for function 'exact_extract': invalid layer names
i Input `pland` is `map2(year_lc, data, calculate_pland, lc = landcover)`.)`

I can not seem to figure out how to correct it, I’m rather new to dense geo-spatial code like this.

There is a free dataset in the link, but I haven’t yet tried it out, so it may be that my data is incompatible with the code? however, I have had a look at the Gis-data.gpkg provided, and my data from gadm seems fine.

The previous two codes to the one above were:

neighborhood_radius <- 5 * ceiling(max(res(landcover))) / 2
 ebird_buff <- red_knot %>% 
     distinct(year = format(observation_date, "%Y"),
              locality_id, latitude, longitude) %>% 
     # for 2019 use 2018 landcover data
     mutate(year_lc = if_else(as.integer(year) > max_lc_year, 
                              as.character(max_lc_year), year),
            year_lc = paste0("y", year_lc)) %>% 
     # convert to spatial features
     st_as_sf(coords = c("longitude", "latitude"), crs = 4326) %>% 
     # transform to modis projection
     st_transform(crs = projection(landcover)) %>% 
     # buffer to create neighborhood around each point
     st_buffer(dist = neighborhood_radius) %>% 
     # nest by year
     nest(data = c(year, locality_id, geometry))
 calculate_pland <- function(yr, regions, lc) {
     locs <- st_set_geometry(regions, NULL)
     exact_extract(lc[[yr]], regions, progress = FALSE) %>% 
         map(~ count(., landcover = value)) %>% 
         tibble(locs, data = .) %>% 

Get this bounty!!!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.