{"action":"created","issue":{"url":"https://api.github.com/repos/tidyverse/dplyr/issues/2990","repository_url":"https://api.github.com/repos/tidyverse/dplyr","labels_url":"https://api.github.com/repos/tidyverse/dplyr/issues/2990/labels{/name}","comments_url":"https://api.github.com/repos/tidyverse/dplyr/issues/2990/comments","events_url":"https://api.github.com/repos/tidyverse/dplyr/issues/2990/events","html_url":"https://github.com/tidyverse/dplyr/issues/2990","id":244635541,"number":2990,"title":"Better handling of units","user":{"login":"Robinlovelace","id":1825120,"avatar_url":"https://avatars2.githubusercontent.com/u/1825120?v=4","gravatar_id":"","url":"https://api.github.com/users/Robinlovelace","html_url":"https://github.com/Robinlovelace","followers_url":"https://api.github.com/users/Robinlovelace/followers","following_url":"https://api.github.com/users/Robinlovelace/following{/other_user}","gists_url":"https://api.github.com/users/Robinlovelace/gists{/gist_id}","starred_url":"https://api.github.com/users/Robinlovelace/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Robinlovelace/subscriptions","organizations_url":"https://api.github.com/users/Robinlovelace/orgs","repos_url":"https://api.github.com/users/Robinlovelace/repos","events_url":"https://api.github.com/users/Robinlovelace/events{/privacy}","received_events_url":"https://api.github.com/users/Robinlovelace/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2017-07-21T10:56:05Z","updated_at":"2017-07-31T18:48:28Z","closed_at":null,"body":"First up: thanks for creating great software that people can help improve but submitting issues like this.\r\n\r\nIssue: **dplyr** does not seem to handle units inately. I'd classify this as feature request rather than a bug.\r\n\r\nI've commented out the working lines to minimise the size of this post!\r\n\r\n``` r\r\nlibrary(dplyr)\r\n#> \r\n#> Attaching package: 'dplyr'\r\n#> The following objects are masked from 'package:stats':\r\n#> \r\n#>     filter, lag\r\n#> The following objects are masked from 'package:base':\r\n#> \r\n#>     intersect, setdiff, setequal, union\r\nlibrary(sf)\r\n#> Linking to GEOS 3.5.1, GDAL 2.1.3, proj.4 4.9.2, lwgeom 2.3.2 r15302\r\n\r\n# Generate data\r\nnc = st_read(system.file(\"shape/nc.shp\", package = \"sf\"))\r\n#> Reading layer `nc' from data source `/home/robin/R/x86_64-pc-linux-gnu-library/3.4/sf/shape/nc.shp' using driver `ESRI Shapefile'\r\n#> Simple feature collection with 100 features and 14 fields\r\n#> geometry type:  MULTIPOLYGON\r\n#> dimension:      XY\r\n#> bbox:           xmin: -84.32385 ymin: 33.88199 xmax: -75.45698 ymax: 36.58965\r\n#> epsg (SRID):    4267\r\n#> proj4string:    +proj=longlat +datum=NAD27 +no_defs\r\nnc$a = st_area(nc)\r\nnc$a_no_units = as.numeric(nc$a)\r\n\r\n# Test with just a numeric query\r\nfilter(nc, a > 2e+09)\r\n#> Error in filter_impl(.data, quo): Evaluation error: both operands of the expression should be \"units\" objects.\r\n# filter(nc, a_no_units > 2e9) # works\r\nnc[nc$a > 2e+09, ]  # also fails in base R\r\n#> Error in Ops.units(nc$a, 2e+09): both operands of the expression should be \"units\" objects\r\n\r\n# Try with base function median and dplyr function ntile filter(nc, a >\r\n# median(a)) # works\r\nfilter(nc, a > ntile(a, 2))\r\n#> Error in filter_impl(.data, quo): Evaluation error: both operands of the expression should be \"units\" objects.\r\n# filter(nc, a_no_units > ntile(a_no_units, 2)) # works\r\n```\r\n\r\nSession info:\r\n\r\n```\r\nsessionInfo()\r\n#> R version 3.4.1 (2017-06-30)\r\n#> Platform: x86_64-pc-linux-gnu (64-bit)\r\n#> Running under: Ubuntu 16.04.2 LTS\r\n#> \r\n#> Matrix products: default\r\n#> BLAS: /usr/lib/openblas-base/libblas.so.3\r\n#> LAPACK: /usr/lib/libopenblasp-r0.2.18.so\r\n#> \r\n#> locale:\r\n#>  [1] LC_CTYPE=en_GB.UTF-8       LC_NUMERIC=C              \r\n#>  [3] LC_TIME=en_GB.UTF-8        LC_COLLATE=en_GB.UTF-8    \r\n#>  [5] LC_MONETARY=en_GB.UTF-8    LC_MESSAGES=en_GB.UTF-8   \r\n#>  [7] LC_PAPER=en_GB.UTF-8       LC_NAME=C                 \r\n#>  [9] LC_ADDRESS=C               LC_TELEPHONE=C            \r\n#> [11] LC_MEASUREMENT=en_GB.UTF-8 LC_IDENTIFICATION=C       \r\n#> \r\n#> attached base packages:\r\n#> [1] stats     graphics  grDevices utils     datasets  methods   base     \r\n#> \r\n#> other attached packages:\r\n#> [1] bindrcpp_0.2 sf_0.5-2     dplyr_0.7.1 \r\n#> \r\n#> loaded via a namespace (and not attached):\r\n#>  [1] Rcpp_0.12.12     knitr_1.16.5     bindr_0.1        magrittr_1.5    \r\n#>  [5] units_0.4-5      geosphere_1.5-5  lattice_0.20-35  R6_2.2.2        \r\n#>  [9] rlang_0.1.1.9000 stringr_1.2.0    udunits2_0.13    tools_3.4.1     \r\n#> [13] rgdal_1.2-8      grid_3.4.1       DBI_0.7          htmltools_0.3.6 \r\n#> [17] yaml_2.1.14      rprojroot_1.2    digest_0.6.12    assertthat_0.2.0\r\n#> [21] tibble_1.3.3     formatR_1.5      glue_1.1.1       evaluate_0.10.1 \r\n#> [25] rmarkdown_1.6    sp_1.2-5         stringi_1.1.5    compiler_3.4.1  \r\n#> [29] backports_1.1.0  pkgconfig_2.0.1\r\n```\r\n"},"comment":{"url":"https://api.github.com/repos/tidyverse/dplyr/issues/comments/319160914","html_url":"https://github.com/tidyverse/dplyr/issues/2990#issuecomment-319160914","issue_url":"https://api.github.com/repos/tidyverse/dplyr/issues/2990","id":319160914,"user":{"login":"krlmlr","id":1741643,"avatar_url":"https://avatars0.githubusercontent.com/u/1741643?v=4","gravatar_id":"","url":"https://api.github.com/users/krlmlr","html_url":"https://github.com/krlmlr","followers_url":"https://api.github.com/users/krlmlr/followers","following_url":"https://api.github.com/users/krlmlr/following{/other_user}","gists_url":"https://api.github.com/users/krlmlr/gists{/gist_id}","starred_url":"https://api.github.com/users/krlmlr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/krlmlr/subscriptions","organizations_url":"https://api.github.com/users/krlmlr/orgs","repos_url":"https://api.github.com/users/krlmlr/repos","events_url":"https://api.github.com/users/krlmlr/events{/privacy}","received_events_url":"https://api.github.com/users/krlmlr/received_events","type":"User","site_admin":false},"created_at":"2017-07-31T18:48:28Z","updated_at":"2017-07-31T18:48:28Z","body":"Better be strict than sorry, IMO an error is the right behavior. Anyway, this really looks like an issue with the units package."}}
{"actor":{"display_login":"krlmlr"}}