Rscript : Why is Error in UseMethod(“extract_”) : being indicated when attempting to use raster::extract?

徘徊边缘 提交于 2019-12-05 15:08:08

Issue may be due to having another package with the same method name, obfuscating the raster extract method.

The tidyr package has an extract method which may conflict with raster's extract method.

Confirm by checking libraries loaded by doing:

>search()




[1] ".GlobalEnv"           **"package:tidyr"**        "package:dplyr"       
 [4] "package:rgeos"        "package:ggplot2"      "package:RColorBrewer"
 [7] "package:animation"    "package:rgdal"        "package:maptools"    
[10] **"package:raster"**       "package:sp"           "tools:rstudio"       
[13] "package:stats"        "package:graphics"     "package:grDevices"   
[16] "package:utils"        "package:datasets"     "package:methods"     
[19] "Autoloads"            "package:base"    

you can also check which extract method is being loaded by typing name of function without brackets (as below, the environment will tell you which package is being used):

> extract

function (data, col, into, regex = "([[:alnum:]]+)", remove = TRUE, 
    convert = FALSE, ...) 
{
    col <- col_name(substitute(col))
    extract_(data, col, into, regex = regex, remove = remove, 
        convert = convert, ...)
}
<environment: namespace:tidyr>

To resolve the error just unload the offending package, in RStudio you can use the following command:

>.rs.unloadPackage("tidyr")

and re-execute the raster extract method:

>jpnpe <- extract(jpnp, jpnb, fun = mean, na.rm = T)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!