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

Using rename() results in error 'could not find function "setnames"' #123

Closed
larspijnappel opened this issue Nov 12, 2019 · 3 comments · Fixed by #125
Closed

Using rename() results in error 'could not find function "setnames"' #123

larspijnappel opened this issue Nov 12, 2019 · 3 comments · Fixed by #125

Comments

@larspijnappel
Copy link

Unfortunately, dtplyr throws the following error when rename() is used:

Error in setnames(copy(_DT1), "mpg", "miles_per_gallon") : could not find function "setnames"

library(dtplyr)
library(dplyr, warn.conflicts = FALSE)

mtcars %>% 
    lazy_dt() %>%
    rename(miles_per_gallon = mpg)
@batpigandme
Copy link
Contributor

Adding a reprex:

library(dtplyr)
library(dplyr, warn.conflicts = FALSE)

mtcars %>% 
  lazy_dt() %>%
  rename(miles_per_gallon = mpg)
#> Source: local data table [?? x 11]
#> Call:   setnames(copy(`_DT1`), "mpg", "miles_per_gallon")
#> Error in setnames(copy(`_DT1`), "mpg", "miles_per_gallon"): could not find function "setnames"

Yeah, it's doing more than just showing the call (works with data.table attached)

library(data.table)
library(dtplyr)
library(dplyr, warn.conflicts = FALSE)

mtcars %>% 
  lazy_dt() %>%
  rename(miles_per_gallon = mpg)
#> Source: local data table [?? x 11]
#> Call:   setnames(copy(`_DT1`), "mpg", "miles_per_gallon")
#> 
#>   miles_per_gallon   cyl  disp    hp  drat    wt  qsec    vs    am  gear
#>              <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1             21       6   160   110  3.9   2.62  16.5     0     1     4
#> 2             21       6   160   110  3.9   2.88  17.0     0     1     4
#> 3             22.8     4   108    93  3.85  2.32  18.6     1     1     4
#> 4             21.4     6   258   110  3.08  3.22  19.4     1     0     3
#> 5             18.7     8   360   175  3.15  3.44  17.0     0     0     3
#> 6             18.1     6   225   105  2.76  3.46  20.2     1     0     3
#> # … with 1 more variable: carb <dbl>
#> 
#> # Use as.data.table()/as.data.frame()/as_tibble() to access results

Created on 2019-11-12 by the reprex package (v0.3.0)

@hadley
Copy link
Member

hadley commented Nov 12, 2019

This should work without loading data.table, so I've reopened to remind me to take a look at it.

@hadley hadley reopened this Nov 12, 2019
@MichaelChirico
Copy link
Contributor

oh my. I think it's a simple typo:

env$setname <- data.table::setnames

Needs to be setnames not setname

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants