eliocamp / metR

Tools for Easier Analysis of Meteorological Fields
https://eliocamp.github.io/metR/
142 stars 22 forks source link

errors when using `geom_streamline` if `ggplot2` is only attached via namespace #133

Closed mbstadler closed 3 years ago

mbstadler commented 3 years ago

Thank you for the great metR package!

I am preparing a pull request for velociraptor (https://github.com/kevinrue/velociraptor/pull/30) that would use metR to visualize RNA velocities estimated from single cell transcriptomics data in reduced dimensional space.

I have run into a problem when using metR::geom_streamline if ggplot2 is only attached via it's namespace. The problem can be reproduced using the following code:

df <- data.frame(expand.grid(x = 1:10, y = 1:10), dx = rnorm(100), dy = rnorm(100))
ggplot2::ggplot(df, ggplot2::aes(x,y)) + ggplot2::geom_point() + metR::geom_streamline(ggplot2::aes(dx = dx, dy = dy))

In a fresh R session without any loaded packages, this throws: Error in coord_munch(coord, data, panel_params) : could not find function "coord_munch". After library(ggplot2) however, things work fine.

My guess is that this is caused by: https://github.com/eliocamp/metR/blob/012bcffaab45899c6ec08badef0e23e4ca93b7d2/R/geom_streamline.R#L298

Would you consider adding the namespace to such calls, e.g. changing the above line to: munched <- ggplot2::coord_munch(coord, data, panel_params) in order to make metR::geom_streamline usable also with non-attached ggplot2?

I am using:

R version 4.0.3 (2020-10-10)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: CentOS Linux 7 (Core)

Matrix products: default
BLAS/LAPACK: /tungstenfs/groups/gbioinfo/Appz/easybuild/software/OpenBLAS/0.3.7-GCC-8.3.0/lib/libopenblas_skylakex-r0.3.7.so

locale:
[1] C

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

other attached packages:
[1] RColorBrewer_1.1-2

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.5        magrittr_2.0.1    maps_3.3.0        tidyselect_1.1.0  munsell_0.5.0     colorspace_2.0-0  R6_2.5.0
 [8] rlang_0.4.9       dplyr_1.0.2       fields_11.6       dotCall64_1.0-0   grid_4.0.3        spam_2.6-0        checkmate_2.0.0
[15] data.table_1.13.4 gtable_0.3.0      metR_0.9.0        ellipsis_0.3.1    fortunes_1.5-4    digest_0.6.27     tibble_3.0.4
[22] lifecycle_0.2.0   crayon_1.3.4      farver_2.0.3      purrr_0.3.4       ggplot2_3.3.2     vctrs_0.3.6       memoise_1.1.0
[29] glue_1.4.2        labeling_0.4.2    compiler_4.0.3    pillar_1.4.7      generics_0.1.0    scales_1.1.1      backports_1.2.1
[36] lubridate_1.7.9.2 pkgconfig_2.0.3
eliocamp commented 3 years ago

Thanks for the catch. The fix is now online on the dev branch (remotes::install_github("eliocamp/metR@dev)).

mbstadler commented 3 years ago

I can confirm that this fixes the issue I had. Thanks for the quick edit!