I am trying to include a map using the ggmap library in knitr:
library(ggmap)
murder = subset(crime, offense='murder')
qmplot(lon, lat, data=murder)
It runs fine outside of knitr, but when I try to run this code chunk in knitr, I get the error:
Error in UseMethod("depth"): no applicable method for 'depth' applied to an object of class "NULL"
And there is no map in the final PDF
I tried wrapping the qmplot line inside of evaluate(...), but that didn't work
Output of library(knitr); sessionInfo()
> library(knitr)
> sessionInfo()
version 3.0.1 (2013-05-16)
Platform: i686-redhat-linux-gnu (32-bit)
locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
[3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8
[5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8
[7] LC_PAPER=C LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
attached base packages:
[1] stats graphics utils datasets grDevices methods base
other attached packages:
[1] knitr_1.2 vimcom_0.9-8 setwidth_1.0-3
loaded via a namespace (and not attached):
[1] digest_0.6.3 evaluate_0.4.3 formatR_0.7 stringr_0.6.2 tools_3.0.1
I also tried running the same code via Rscript (i.e. not from within VIM) with the following:
Rscript -e "library(knitr); knit('map.Rnw')"
And I get a similar error:
Error in UseMethod("depth") :
no applicable method for 'depth' applied to an object of class "NULL"
Calls: knit ... grid.draw -> grid.draw.gTableChild -> upViewport -> depth
Using ggmap v 2.3 and ggplot v 0.9.3.1
library(knitr); sessionInfo()
. – Borsggmap
isv2.3
? this is weird; I have almost exactly the same environment as you, but I still cannot reproduce the problem – Bors