- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to deal with “could not find function” error in R?
The error “could not find function” occurs due to the following reasons −
Function name is incorrect. Always remember that function names are case sensitive in R.
The package that contains the function was not installed. We have to install packages in R once before using any function contained by them. It can be done as install.packages("package_name")
The package was not loaded before using the function. To use the function that is contained in a package we need to load the package and it can be done as library("package_name").
Version of R is older where the function you are using does not exist.
If you have installed and loaded many packages but forgot which package contains the function you are using then you can do it by using getAnywhere
Example
> library(ggplot2) > library(BSDA) Loading required package: lattice Attaching package: ‘BSDA’
The following object is masked from ‘package:datasets’ −
Orange
> library(purrr) > getAnywhere(ggplot) A single object matching ‘ggplot’ was found It was found in the following places package:ggplot2 namespace:ggplot2 with value function (data = NULL, mapping = aes(), ..., environment = parent.frame()){ UseMethod("ggplot") } <bytecode: 0x0000000011201848> <environment: namespace:ggplot2>
Here we have loaded three packages, named ggplot2, BSDA, and purr. Suppose we wanted to know which package contains ggplot function. So, we used getAnywhere and it returns the package name as ggplot2.
You should make sure that you do not make the mistakes mentioned above. If you use an older version of R but want to perform calculations using a function that is created for a newer version then it would not be possible. But it can become possible if you use package backports to make newly added functions available to older version of R. Also, you need to find the list of function that need to be backported on the git repo of backports. Just remember that R versions older than R3.0.0 are not compatible with packages built for R3.0.0 and later versions.
- Related Articles
- How to deal with the error “Error in int_abline---plot.new has not been called yet” in R?
- How to deal with error invalid xlim value in base R plot?
- How to deal with error “Error in eval(predvars, data, env) : numeric 'envir' arg not of length one” in R?
- How to deal with error “$ operator is invalid for atomic vectors” in R?
- How to deal with error “undefined columns selected” while subsetting data in R?
- How to deal with error “Error in shapiro.test(…) : sample size must be between 3 and 5000” in R?
- How to deal with error “undefined columns selected when subsetting data frame” in R?
- How to deal with glm.fit error “NA/NaN/Inf” for logistic regression model in R?
- How to deal with Error: stat_count() can only have an x or y aesthetic in R?
- What is Xcode error “Could not find Developer Disk Image”?
- How to deal with error “var(x) : Calling var(x) on a factor x is defunct.” in R?
- How to deal with NA output of apply in R?
- How to deal with missing values to calculate correlation matrix in R?
- How to deal with hist.default, 'x' must be numeric in R?
- How to find the standard error of mean in R?
