错误:在 R 中找不到函数... [英] Error: could not find function ... in R

查看:29
本文介绍了错误:在 R 中找不到函数...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个常见问题解答问题,因此请尽可能完整.答案是社区答案,因此如果您认为缺少某些内容,请随时进行编辑.

此问题已在元上讨论并获得批准.

我正在使用 R 并尝试了 some.function 但我收到以下错误消息:

I am using R and tried some.function but I got following error message:

Error: could not find function "some.function"

这个问题经常出现.当你在 R 中遇到这种类型的错误时,你如何解决它?

This question comes up very regularly. When you get this type of error in R, how can you solve it?

推荐答案

您应该检查以下几点:

  1. 你的函数名写对了吗?名称区分大小写.
  2. 您是否安装了包含该功能的软件包?install.packages(thePackage")(这只需要做一次)
  3. 您是否将该包附加到工作区?require(thePackage)(并检查其返回值)或 library(thePackage)(每次开始新的 R 会话时都应该这样做)
  4. 您是否在使用尚不存在此功能的旧 R 版本?
  5. 您使用的是特定的不同版本吗?这可能是两个方向:函数会随着时间的推移而添加和删除,并且您引用的代码可能需要比您已安装的包更新或旧版本.
  1. Did you write the name of your function correctly? Names are case sensitive.
  2. Did you install the package that contains the function? install.packages("thePackage") (this only needs to be done once)
  3. Did you attach that package to the workspace ? require(thePackage) (and check its return value) or library(thePackage) (this should be done every time you start a new R session)
  4. Are you using an older R version where this function didn't exist yet?
  5. Are you using a different version of the specific package? This could be in either direction: functions are added and removed over time, and it's possible the code you're referencing is expecting a newer or older version of the package than what you have installed.

如果您不确定该函数位于哪个包中,您可以做一些事情.

If you're not sure in which package that function is situated, you can do a few things.

  1. 如果您确定安装并附加/加载了正确的软件包,请输入 help.search("some.function")??some.function获取一个信息框,可以告诉您它包含在哪个包裹中.
  2. findgetAnywhere 也可用于定位函数.
  3. 如果您对软件包一无所知,您可以使用 sos 软件包中的 findFn,如 这个答案.
  4. RSiteSearch("some.function") 或使用 rdocumentation 搜索或rseek 是查找函数的替代方法.
  1. 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.
  2. find and getAnywhere can also be used to locate functions.
  3. If you have no clue about the package, you can use findFn in the sos package as explained in this answer.
  4. RSiteSearch("some.function") or searching with rdocumentation or rseek are alternative ways to find the function.

有时您需要使用旧版本的 R,但运行为新版本创建的代码.新添加的函数(例如 R 3.4.0 中的 hasName)将不会被找到.如果您使用较旧的 R 版本并想使用较新的功能,则可以使用包 backports 使这些功能可用.您还可以在 git 存储库中找到需要向后移植的函数列表向后移植.请记住,早于 R3.0.0 的 R 版本与为 R3.0.0 及更高版本构建的包不兼容.

Sometimes you need to use an older version of R, but run code created for a newer version. Newly added functions (eg hasName in R 3.4.0) won't be found then. If you use an older R version and want to use a newer function, you can use the package backports to make such functions available. You also find a list of functions that need to be backported on the git repo of backports. Keep in mind that R versions older than R3.0.0 are incompatible with packages built for R3.0.0 and later versions.

这篇关于错误:在 R 中找不到函数...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆