There are a few things you should check :
- 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)
or library(thePackage)
(this should be done every time you start a new R session)
- Are you using an older R version where this function didn't exist yet?
If you're not sure in which package that function is situated, you can do a few things.
- 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
and getAnywhere
can also be used to locate functions.
- If you have no clue about the package, you can use
findFn
in the sos
package as explained in this answer.
RSiteSearch("some.function")
or searching with rdocumentation or rseek are alternative ways to find the function.
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.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…