[GIS] Function argument for all values in R (raster extract, and velox raster extract)

r

I'm using the package velox to speed up raster extraction.

Simple question (and probably an easy one): what is the argument in R for fun=all values?

Context:
In the raster package the function extract fun=NULL is to return all pixel values. In velox the extract requires an argument "fun=". What is the function argument that will return all the cell values like the fun=NULL of the extract in the raster package?

Bonus points if you have a function that will take the mean while ignoring NA values (which is what I'm trying to do anyhow). Something along the lines of

meanvalue <- raster::extract(testraster, testpoly, fun=mean if x !=NA)

Id then use it on a velox raster (should work the same) like this rather than the above code:

meanvalue <- velox.testraster$extract(testpoly, fun=mean if x !=NA)

Fun=mean doesn't work because some of my polygons have NA values for pixels since they are not covered by the raster.

Best Answer

Got it:

fun <- function(x){mean(x, na.rm=TRUE)})

for velox:

sample.list <- sampleVeloxraster$extract(sampleshp, fun=function(x){mean(x, na.rm=TRUE)})