Giter Site home page Giter Site logo

.data pronoun does not work about dbplyr HOT 3 CLOSED

tidyverse avatar tidyverse commented on May 29, 2024 1
.data pronoun does not work

from dbplyr.

Comments (3)

sverchkov avatar sverchkov commented on May 29, 2024

Looking into it I gathered that what happens is that the error is triggered because partial_eval eventually calls lang_partial_eval which calls bare_eval because of the $ in the expression.
As far as I can tell the .data pronoun never gets installed before that so it tries to get .data$column from the empty .data pronoun that rlang creates globally, hence the message.

There's a workaround (creating a data pronoun manually) that seems to work for most dplyr verbs, but fails with select and distinct:

var_strs <- dbplyr::op_vars(mtcars2)
x <- syms( var_strs )
names( x ) <- var_strs
my_pronoun <- rlang::as_data_pronoun( x )

# Now this works, as do most other dplyr verbs
mutate( mtcars2, foo = my_pronoun$cyl )

# But these fail:
select( mtcars2, my_pronoun$cyl )
# Error: `my_pronoun$cyl` must evaluate to column positions or names, not a symbol

distinct( mtcars2, my_pronoun$cyl )
# Error in result_create(conn@ptr, statement) : no such column: my_pronoun$cyl

select fails here because, unlike the other verbs, it never calls partial_eval, and the error message is coming from tidyselect::vars_select().

distinct apparently uses the names and not the values of the object that partial_eval returns. It also means that
distinct( mtcars2, cyl = anything )
functions identically to distinct( mtcars2, cyl ), which is not consistent with how the dataframe version works.

from dbplyr.

hadley avatar hadley commented on May 29, 2024

Minimal reprex:

library(dplyr, warn.conflicts = FALSE)
mf <- dbplyr::memdb_frame(a = 1, b = 2)

mutate(mf, foo = .data$a)
#> Error in if (length(ans) == 0L || as.character(ans[[1L]])[1L] == "~") {: missing value where TRUE/FALSE needed

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

This probably requires special treatment of the $ translation when the LHS is .data or .env

from dbplyr.

hadley avatar hadley commented on May 29, 2024

And hence this is part of #200

from dbplyr.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.