When you encounter the error could not find function in R, it means R doesn’t know where to find the function you’re trying to use. Below are two common reasons this happens and how to fix the problem.
Many functions live inside specific packages. If you don’t load the package into your current R session, R doesn’t know the function exists.
Here’s an example attempting to use the glimpse function from the dplyr package, before the dplyr package has been loaded in the current session:
To address this, you need to load the dplyr package into your current R session via the library command:
library(dplyr)
If this yields an error telling you there is no package called dplyr, it means you have not yet installed that package on your computer:
Error in library(dplyr) : there is no package called ‘dplyr’
To address that, use install.packages (make sure you surround the package name in quotes):
install.packages("dplyr")
Then re-run the library command:
library(dplyr)
If you’re unsure what package a function belongs to, try searching online or asking an AI program “What R package does [function name] belong to?”
Another common reason you might encounter a could not find function error in R is because function names are case-sensitive and must be spelled exactly right.
For example, Glimpse(mtcars) will not work, even if the dplyr package is loaded. You must use the correct lowercase spelling: glimpse(mtcars).
No subscriptions, no auto-renewals.
Just a simple one-time payment that helps support my free, to-the-point videos without sponsered ads.
Unlocking gets you access to the notes for this video plus all 200+ guides on this site.
Your support is appreciated. Thank you!