1

I just updated dplyr and it seems like the most basic functions don't work for me anymore. Namely, I'm trying to rename variables in R using dplyr and I have the code set up like this:

df = df %>% 
  rename(
    newname = oldname
  )

This code worked fine for older versions of dplyr but now that it's on v.1.0.0 I have no idea why, but it's just giving me:

Error in rename(., newname = oldname) : 
  unused argument (newname = oldname)

I checked the newest tutorials and they seem to still suggest that the old format works, so I'm not sure what's going on. My R program is updated and currently on version 4.0. Is there a way to downgrade my dplyr package to the older versions where this code worked?

I can load the data with the following:

data(iris)
head(iris)
  Sepal.Length Sepal.Width Petal.Length Petal.Width Species
1          5.1         3.5          1.4         0.2  setosa
2          4.9         3.0          1.4         0.2  setosa
3          4.7         3.2          1.3         0.2  setosa
4          4.6         3.1          1.5         0.2  setosa
5          5.0         3.6          1.4         0.2  setosa
6          5.4         3.9          1.7         0.4  setosa

iris = iris %>%
   rename(
     sepal_width = Sepal.Width
   )

which promptly gives me the error message.

ssjjaca
  • 219
  • 1
  • 6
  • 1
    Please show a small reproducible example – akrun Jun 04 '20 at 18:53
  • 3
    `mtcars %>% rename(cyl2=cyl)` works for me, my guess is that you've also loaded `plyr`, [in the wrong order](https://github.com/tidyverse/dplyr/issues/347). Type in `rename` (nothing else) and confirm that it says either `` (this is likely your problem) or `` (in which case there is another problem going on). – r2evans Jun 04 '20 at 18:59
  • 1
    @r2evans That fixed it! Yes, I had plyr loaded as the environment. I detached the package and now it works again. Thanks a bunch! – ssjjaca Jun 04 '20 at 19:03
  • While the name is not a perfect match, the symptom is: https://stackoverflow.com/q/26923862/3358272 (the dupe question talks about `summarize` and not `rename`, but it's the same thing). – r2evans Jun 05 '20 at 04:49

1 Answers1

0

I run your script on my computer and it works without problems, I have version 0.8.5. To install a previous version of Dplyr (and any package) you should search CRAN for the ejectuable of a previous version. In your case, the version of Dplyr 0.8.5 can be downloaded from this link: https://cran.r-project.org/src/contrib/Archive/dplyr/dplyr_0.8.5.tar.gz To install it you should save it in the working directory and execute the following code:

install.packages ("dplyr_0.8.5.tar.gz", repos = NULL)

Update my version of Dplyr to 1.0 and it can run your program without problems. Maybe the problem is different but I don't realize that it could be ...