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

匿名 (未验证) 提交于 2019-12-03 01:57:01

问题:

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"’

In most cases I've been able to solve my issues by finding alternate examples online, but I'd like to understand what the error message means so I can better understand how R works.

For example, this code:

library("RSQLite") con = dbConnect(drv="SQLite", dbname="database.db")

Generates this warning:

unable to find an inherited method for function ‘dbConnect’ for signature ‘"character"’

And after fixing that error, this code:

dbClearResult(p1)

Produces this warning:

unable to find an inherited method for function ‘dbClearResult’ for signature ‘"data.frame"’

Can somebody please explain what this type of error message is trying to tell me?

Specifically, the terms "interhited", "method", "function", and "signature" all seem related to concepts I understand from other languages, but the sentence structure of this error implies they have slightly different meanings in R.

回答1:

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 


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!