Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dplyr::case_when() combined with mutate() does not work when applied to tbl #3736

Closed
CarolineBarret opened this issue Aug 2, 2018 · 3 comments

Comments

@CarolineBarret
Copy link

CarolineBarret commented Aug 2, 2018

I am working with R 3.4.3 and dplyr 0.7.4.

I am trying to apply the case_when() function to a tibble object from a database. But when I combine the case_when() function to the mutate() function, I get an error:

dir.create("tmp")
# The datasets.sqlite is just a sqlite database 
# It contains a table called iris with the iris data frame in it
file.copy("data/datasets.sqlite", "tmp")

# Connect to the database
con <- DBI::dbConnect(RSQLite::SQLite(), "tmp/datasets.sqlite")

cake <- dplyr::mutate(dplyr::tbl(con, "iris"),
                        type = dplyr::case_when(
        Sepal.Length > 5.8 | Petal.Length > 3.7 ~ "long",
        Sepal.Width > 3  | Petal.Width > 1.2 ~ "wide",
        TRUE ~  "other"
      )
    )

This gives me the following error: Error in eval_bare(f[[2]], env) : object 'Sepal.Length' not found

I think this is to do with the fact that I use mutate() because I do not get an error with the following:

  ir <- dplyr::tbl(con, "iris")
  cake <- dplyr::case_when(
                          ir$Sepal.Length > 5.8 | ir$Petal.Length > 3.7 ~ "long",
                          ir$Sepal.Width > 3  | ir$Petal.Width > 1.2 ~ "wide",
                          TRUE ~  "other"
                        )

It also is to do with tibbles output (and not with data.frames), because this works fine too:

  cake <- dplyr::mutate(DBI::dbReadTable(con, "iris"),
                        type = dplyr::case_when(
                          Sepal.Length > 5.8 | Petal.Length > 3.7 ~ "long",
                          Sepal.Width > 3  | Petal.Width > 1.2 ~ "wide",
                          TRUE ~  "other"
                        )
  )
@krlmlr
Copy link
Member

krlmlr commented Aug 2, 2018

Thanks, this seems related to the database backend only.

/move to dbplyr

@ghost
Copy link

ghost commented Aug 2, 2018

This issue was moved by krlmlr to tidyverse/dbplyr#135.

@ghost ghost closed this as completed Aug 2, 2018
@lock
Copy link

lock bot commented Jan 29, 2019

This old issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with reprex) and link to this issue. https://reprex.tidyverse.org/

@lock lock bot locked and limited conversation to collaborators Jan 29, 2019
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants