What does this mean: unable to find an inherited method for function ‘A’ for signature ‘“B”’

前端 未结 2 1034
清歌不尽
清歌不尽 2020-12-03 10:56

I am new to R and keep getting errors with the following message:

unable to find an inherited method for function ‘A’ for signature ‘\"B\"’

2条回答
  •  没有蜡笔的小新
    2020-12-03 11:03

    That is the type of message you will get when attempting to apply an S4 generic function to an object of a class for which no defined S4 method exists (or at least has been attached to the current R session).

    Here's an example using the raster package (for spatial raster data), which is chock full of S4 functions.

    library(raster)
    
    ## raster::rotate() is an S4 function with just one method, for "Raster" class objects
    isS4(rotate)
    # [1] TRUE
    showMethods(rotate)
    # Function: rotate (package raster)
    # x="Raster"
    
    ## Lets see what happens when we pass it an object that's *not* of class "Raster"
    x <- 1:10
    class(x)
    # [1] "integer"
    rotate(x)
    # Error in (function (classes, fdef, mtable)  : 
    #   unable to find an inherited method for function ‘rotate’ for signature ‘"integer"’
    

提交回复
热议问题