错误:在R中找不到功能
问题描述:
我正在使用R并尝试 some.function
但我收到此错误消息:
I am using R and tried some.function
but I got this error message :
Error: could not find function `some.function`
这个问题出现很经常当您得到错误:在R中找不到函数
时,您如何解决?
This question comes up very regularly. When you get the error: could not find function
in R, how can you solve it?
谢谢提前为您的帮助。
这是一个常见问题,所以请尽可能完整。答案是一个社区答案,如果你觉得缺少某些东西,请随时编辑。
HREF = https://meta.stackexchange.com/questions/101892/community-wiki-with-common-error-messages-allowed> https://meta.stackexchange.com/questions/101892/community-wiki-允许共同错误消息
答
有几件事你应该检查:
- 您的函数名称是否正确写入?名称区分大小写。
- 您是否安装了包含该功能的包?
install.packages(thePackage)
(这只需要完成一次) - 您是否将该附件附加到工作区?
require(thePackage)
或库(thePackage)
(每当你启动一个新的R会话)
- Did you write the name of your function correctly? Names are case sensitive.
- Did you install the package that contains the function?
install.packages("thePackage")
(this only needs to be done once) - Did you attach that package to the workspace ?
require(thePackage)
orlibrary(thePackage)
(this should be done every time you start a new R session)
如果您不确定该功能所在的包,您可以做一些事情。 >
If you're not sure in which package that function is situated, you can do a few things.
- 如果您确定已安装并加载正确的软件包,请键入
help.search(some.function )
或?? some.function
以获取一个信息框,可以告诉您包含哪个包。 -
find
和getAnywhere
也可用于查找功能。 - 如果你没有关于包的线索,可以在
sos
包中使用findFn
,如这个答案。 -
RSiteSearch(some.function)
或使用 rseek 进行搜索替代方法找到该功能。
- If you're sure you installed and attached/loaded the right package, type
help.search("some.function")
or??some.function
to get an information box that can tell you in which package it is contained. -
find
andgetAnywhere
can also be used to locate functions. - If you have no clue about the package, you can use
findFn
in thesos
package as explained in this answer. -
RSiteSearch("some.function")
or searching with rseek are alternative ways to find the function.