Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
632 views
in Technique[技术] by (71.8m points)

r - What does this mean: unable to find an inherited method for function ‘A’ for signature ‘"B"’

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...