ggmap error (Error in as.vector(y) : attempt to apply non-function)
Asked Answered
T

4

10

I'm doing relatively simple things with ggmap and am confused because code that runs fine on my mac does not run on my PC.

I run this code:

library(ggmap)

map <- get_map(location = c(-122.175, 37.45635),
               maptype = "terrain",
               source = "google",
               crop = FALSE,
               zoom = 7)
 ggmap(map)

, which runs fine on my mac, but throws this error on my PC:

Error in as.vector(y) : attempt to apply non-function

Any help would be much appreciated.

Tunis answered 15/11, 2016 at 16:9 Comment(2)
Unable to reproduce, works fine on my Windows machine. Try restarting R, or reinstalling the package.Houck
Right, it works fine on my mac as well + I of course already tried restarting R and restarting my computer. That's why I posted the question - to see if anyone might have any ideas on what could be going wrong on a PC. Thanks though.Tunis
H
3

It is no longer necessary to uninstall ggplot2 to fix this error. I was able to update ggplot by running install.packages("ggplot2"), then reinstall ggmap. This solved the problem for me.

Hast answered 24/2, 2017 at 19:10 Comment(1)
I confirm that updating from ggplot2 2.1.0 to ggplot2 2.2.1 also worked for me.Rutheruthenia
T
2

I faced that problem after installing R and RStudio last week. Restarting RStudio or R session, or reinstalling ggmap package didn't work for me. I'd just fixed it with these steps:

  • Uninstall R and RStudio
  • Delete old folders related to R and RStudio in Program Files (I had things like older versions of R).
  • Delete Windows temporary files (just in case)
  • Install R and RStudio again
  • Install ggmap package
Thermobarograph answered 17/11, 2016 at 7:49 Comment(1)
Thank you! This is what ended up working on my work PC. Whew :)Tunis
A
1

I guess this problem comes from the last update of ggplot2. See the following links:

You could try to install an older version of ggplot (see below) or try to reinstall the packages like suggested in the link above.

    library(devtools)
    install_version("ggplot2", version = "2.1.0", repos = "http://cran.us.r-project.org")
Ankus answered 17/11, 2016 at 11:11 Comment(2)
Yes, I ended up then having this same trouble on my mac and this solution also worked for me -- thank you! (But also a bummer that I can't also utilize the new ggplot2 features - oh welll - this is what iterations are for I suppose!)Tunis
My experience seems to be the opposite (in Windows with RStudio): I had this error with ggplot2 2.1.0 and solved it by upgrading to ggplot2 2.2.1.Rutheruthenia
D
1

You don't need to Unistall R. Just erase ALL folders related to ggplot2, and reinstall the ggmap with all dependencies.

Deil answered 5/12, 2016 at 18:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.