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

Cannot rename multiple variables in one step with SQL sources. #2943

Closed
iangow opened this issue Jul 5, 2017 · 2 comments
Closed

Cannot rename multiple variables in one step with SQL sources. #2943

iangow opened this issue Jul 5, 2017 · 2 comments
Labels
bug an unexpected problem or unintended behavior

Comments

@iangow
Copy link

iangow commented Jul 5, 2017

Cannot rename multiple variables in one step with SQL sources. Can do it one variable at a time. SQL generated seems fine, however. See reprex below.

I get the same error message with RPostgreSQL:

Error in names(select)[match(old_vars, vars)] <- new_vars: NAs are not allowed in subscripted assignments

library(RSQLite)
#> Warning: package 'RSQLite' was built under R version 3.4.1
con <- dbConnect(SQLite(), ":memory:")

library(dplyr, warn.conflicts = FALSE)

mtcars_mem <- copy_to(con, mtcars)

mtcars_mem %>%
    rename(disp2 = disp) %>%
    rename(hp2 = hp)
#> # Source:   lazy query [?? x 11]
#> # Database: sqlite 3.19.3 [:memory:]
#>      mpg   cyl disp2   hp2  drat    wt  qsec    vs    am  gear  carb
#>    <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
#>  1  21.0     6 160.0   110  3.90 2.620 16.46     0     1     4     4
#>  2  21.0     6 160.0   110  3.90 2.875 17.02     0     1     4     4
#>  3  22.8     4 108.0    93  3.85 2.320 18.61     1     1     4     1
#>  4  21.4     6 258.0   110  3.08 3.215 19.44     1     0     3     1
#>  5  18.7     8 360.0   175  3.15 3.440 17.02     0     0     3     2
#>  6  18.1     6 225.0   105  2.76 3.460 20.22     1     0     3     1
#>  7  14.3     8 360.0   245  3.21 3.570 15.84     0     0     3     4
#>  8  24.4     4 146.7    62  3.69 3.190 20.00     1     0     4     2
#>  9  22.8     4 140.8    95  3.92 3.150 22.90     1     0     4     2
#> 10  19.2     6 167.6   123  3.92 3.440 18.30     1     0     4     4
#> # ... with more rows

mtcars_mem %>%
    rename(disp2 = disp, hp2 = hp)
#> Error in names(select)[match(old_vars, vars)] <- new_vars: NAs are not allowed in subscripted assignments

mtcars_mem %>%
    rename(disp2 = disp, hp2 = hp) %>%
    show_query()
#> <SQL>
#> SELECT `mpg` AS `mpg`, `cyl` AS `cyl`, `disp` AS `disp2`, `hp` AS `hp2`, `drat` AS `drat`, `wt` AS `wt`, `qsec` AS `qsec`, `vs` AS `vs`, `am` AS `am`, `gear` AS `gear`, `carb` AS `carb`
#> FROM `mtcars`
@krlmlr
Copy link
Member

krlmlr commented Jul 12, 2017

Thanks, confirmed. Slightly simpler reprex:

library(magrittr)
dbplyr::memdb_frame(a = 1, b = 2) %>% dplyr::rename(c = a, d = b)
#> Error in names(select)[match(old_vars, vars)] <- new_vars: NAs are not allowed in subscripted assignments

@hadley
Copy link
Member

hadley commented Oct 24, 2017

Fixed in tidyverse/dbplyr@e97f408

@hadley hadley closed this as completed Oct 24, 2017
@lock lock bot locked as resolved and limited conversation to collaborators Jun 7, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug an unexpected problem or unintended behavior
Projects
None yet
Development

No branches or pull requests

3 participants