bcgov / bcdata

An R package for searching & retrieving data from the B.C. Data Catalogue
https://bcgov.github.io/bcdata
Apache License 2.0
81 stars 12 forks source link

partial evaluation doing strange things when RHS needs to be subset #60

Closed ateucher closed 5 years ago

ateucher commented 5 years ago
library(bcdata)
#> 
#> Attaching package: 'bcdata'
#> The following object is masked from 'package:stats':
#> 
#>     filter

x <- c("airport", "heliport")
bcdc_query_geodata("bc-airports") %>% 
  filter(DESCRIPTION == x[1]) %>% 
  show_query()
#> <url> 
#> https://openmaps.gov.bc.ca/geo/pub/wfs?
#> SERVICE=WFS&
#> VERSION=2.0.0&
#> REQUEST=GetFeature&
#> outputFormat=application%2Fjson&
#> typeNames=WHSE_IMAGERY_AND_BASE_MAPS.GSR_AIRPORTS_SVW&
#> SRSNAME=EPSG%3A3005
#> <SQL> 
#> ("DESCRIPTION" = CASE WHEN (1.0) THEN (('airport', 'heliport')) END)

y <- data.frame(type = c("airport", "heliport"))
bcdc_query_geodata("bc-airports") %>% 
  filter(DESCRIPTION %in% y$type) %>% 
  show_query()
#> Error in UseMethod("escape"): no applicable method for 'escape' applied to an object of class "data.frame"

Created on 2019-05-02 by the reprex package (v0.2.1)

ateucher commented 5 years ago

This is actually a 'feature' of the latest dbplyr release - the intention is to evaluate tables with those names in the backend database. To evaluate them locally, they need to be unquoted:

library(bcdata)
#> 
#> Attaching package: 'bcdata'
#> The following object is masked from 'package:stats':
#> 
#>     filter

x <- c("airport", "heliport")
bcdc_query_geodata("bc-airports") %>% 
  filter(DESCRIPTION == !!x[1]) %>% 
  show_query()
#> Warning: It is advised to use the permanent id ('76b1b7a3-2112-4444-857a-
#> afccf7b20da8') rather than the name of the record ('bc-airports')to guard
#> against future changes
#> <url> 
#> https://openmaps.gov.bc.ca/geo/pub/wfs?
#> SERVICE=WFS&
#> VERSION=2.0.0&
#> REQUEST=GetFeature&
#> outputFormat=application%2Fjson&
#> typeNames=WHSE_IMAGERY_AND_BASE_MAPS.GSR_AIRPORTS_SVW&
#> SRSNAME=EPSG%3A3005
#> <SQL> 
#> ("DESCRIPTION" = 'airport')

y <- data.frame(type = c("airport", "heliport"))
bcdc_query_geodata("bc-airports") %>% 
  filter(DESCRIPTION %in% !!y$type) %>% 
  show_query()
#> <url> 
#> https://openmaps.gov.bc.ca/geo/pub/wfs?
#> SERVICE=WFS&
#> VERSION=2.0.0&
#> REQUEST=GetFeature&
#> outputFormat=application%2Fjson&
#> typeNames=WHSE_IMAGERY_AND_BASE_MAPS.GSR_AIRPORTS_SVW&
#> SRSNAME=EPSG%3A3005
#> <SQL> 
#> ("DESCRIPTION" IN ('airport', 'heliport'))

Created on 2019-05-02 by the reprex package (v0.2.1)

ateucher commented 5 years ago

E.g. https://github.com/tidyverse/dbplyr/issues/291 & https://github.com/tidyverse/dbplyr/issues/289

ateucher commented 5 years ago

63 should revert the behaviour for our use case here so we don't need !!