Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

r

ggmap

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.

like image 344
leb112358 Avatar asked Nov 15 '16 16:11

leb112358


3 Answers

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.

like image 180
StatisticianInStilettos Avatar answered Oct 04 '22 20:10

StatisticianInStilettos


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
like image 41
Martin Ehman Avatar answered Oct 04 '22 22:10

Martin Ehman


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

  • https://github.com/tidyverse/ggplot2/blob/master/NEWS.md#extensions
  • ggmap Error: GeomRasterAnn was built with an incompatible version of ggproto

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")
like image 41
Benjamin Ziepert Avatar answered Oct 04 '22 20:10

Benjamin Ziepert