could not find function "ggplot"

#1

Hi guys,
I am coding with R. My code worked untill yestarday.
Today I'm getting the following error:

Error in ggplot(data = working_data, aes(x = working_data$Column1, :
could not find function "ggplot"

I have installed:
install.packages("tidyverse")
install.packages("ggplot2")
library(ggplot2)
library(tidyverse)

but nothing, it doesn't work.

I tried to remove packages, but, again, I'm getting 'ggplot2' not found.

I have done some updates, could it be this the reason?

Thank you so much for your help!
Regards

0 Likes

#2

I think we need a little more information to help you, have you updated R itself since yesterday? What version of R are you using now? On which operating system are you? What is the output of running this command on the R console?

.libPaths() 
0 Likes

#3

Thank you andresrcs,
R version 3-5-1
Windows 10 Pro
Output: [..] Desktop/R-3.5.1/library
Yep, in the last two days I run some updates in R
thank you for your help!

0 Likes

#4

When you update R on windows the packages you have installed for the previous version are not available for the new one out of the box, you have to manually move them to the new location or point libpath to the old location.
Just to clarify are this the steps you have taken so far?

remove.packages("ggplot2") # Unisntall ggplot
install.packages("ggplot2") # Install it again
library(ggplot2) # Load the librarie (you have to do this one on each new session)
0 Likes

#5

Do you know about sessions? For example, did you run library(ggplot2) earlier, close R Studio, then open it up again? Code run in a previous session won't be run when you start a new one.

This can be surprising, because R likes to push "workspace images" as a default behavior; when you exit a session, you may be asked, "Save workspace image?" This creates a file named .RData in the working directory which stores all the objects in your session's environment. Whenever you start a new session in that directory, it will automatically load them. But it won't reload packages.

If you haven't already, I'd suggest disabling this behavior and the pop-up window. In RStudio, go to Tools > Global Options > General. Then uncheck "Restore .RData into workspace at startup" and set "Save workspace to .RData on exit" to "Never."

workspace-settings

The best practice is to write scripts that can recreate the work each time. This reduces the chance of unpleasant surprises from leftover objects in the workspace. If you do need to save data (e.g. it takes half an hour to create a dataset), use the save() and load() functions in your script. That way, anyone reading it (including future you) will know what's going on.

0 Likes

#6

Yep!
When I run
library(ggplot2)
I get:
Error: package or namespace load failed for ‘ggplot2’ in loadNamespace(i, c(lib.loc, .libPaths()), versionCheck = vI[[i]]):
there is no package called ‘colorspace’
In addition: Warning message:
package ‘ggplot2’ was built under R version 3.5.3

I don't know if this message could help us to understand.
Thank you again!

0 Likes

#7

That error message is different, you have to install the missing dependency

install.packages("colorspace")

Also, there is some discrepancy here, you said that you have R 3.5.1 but the message says that you have installed ggplot2 under R 3.5.3, could you clarify?

0 Likes

#8

Hi nwerth,
I clicked "No" when "Save workspace image?" was asked to me.
Thank you

0 Likes

#9

Thank you for your feedback

When I open R, there is written: R version 3.5.1 (2018-07-02) -- "Feather Spray" [...]. For this reason, I don't know why I get the error "package ‘ggplot2’ was built under R version 3.5.3". It is one of my doubts.

0 Likes

#10

It seems to be the solution. Thank you!

0 Likes

#11

If your question's been answered (even by you!), would you mind choosing a solution? It helps other people see which questions still need help, or find solutions if they have similar problems. Here’s how to do it:

0 Likes

#12

thanks!
Could you help me to understand the problem with the R version?

0 Likes

#13

That's not actually an issue (as far as I can see).

R packages issue warnings when the version of R they were built on are more recent than the one you have installed. The majority of the time this is not a problem, so hence it's only a warning. However, it is possible that some things will not work correctly if they rely on features from the more recent version of R.

0 Likes

closed #14

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.

0 Likes