Extract Raster Pixels Values Using Vector Polygons in R

Glad you fixed it. Please mark the solution for the benefit of those to follow. No false modesty allowed.

For the data part of it: Only enough data to reproduce the issue is needed. It doesn't have to be your data, one of the built in datasets with comparable structure will do. It doesn't have to be all of the data, just enough to show the same behavior. And, as an added bonus.

dput(your_data

Will return a formal definition of the data object, which can be cut and pasted into the code reprex with

dput(your_data

followed by paste.

Here's a function with a slightly less verbose output:

require(clipr)
#> Loading required package: clipr
#> Welcome to clipr. See ?write_clip for advisories on writing to the clipboard in R.
require(magrittr)
#> Loading required package: magrittr
require(stringr)
#> Loading required package: stringr

specimen <- function(x)
  deparse(x) %>%
  str_c(collapse = '') %>%
  str_replace_all('\\s+', ' ') %>%
  str_replace_all('\\s*([^,\\()]+ =) (c\\()', '\n  \\1\n    \\2')  %>%
  str_replace_all('(,) (class =)', '\\1\n  \\2') %>%
  write_clip(allow_non_interactive = TRUE) 

(Credit to the anonymous author from whom I ripped off at least the major pieces. Mea culpa.)