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 deprecated function rbind_all of dplyr package which is no longer supported and code fails #306

Open
shafayetShafee opened this issue Jun 14, 2022 · 4 comments

Comments

@shafayetShafee
Copy link
Contributor

Code snippet from 1.6.3 Profiling contains a function dplyr::rbind_all() which is no longer supported the current version of dplyr package.

Code snippet from book

library("profvis")
profvis(expr = {

  library("ggplot2")
  out = readRDS("extdata/out-ice.Rds")
  df = dplyr::rbind_all(out, id = "Year")

  ggplot(df, aes(long, lat, group = paste(group, Year))) +
    geom_path(aes(colour = Year))
  ggsave("figures/icesheet-test.png")
}, interval = 0.01, prof_output = "ice-prof")

When tried to create a dataframe from out using rbind_all got the following error

extdata_path <- "https://raw.githubusercontent.com/csgillespie/efficientR/master/extdata/"
out <- readr::read_rds(paste0(extdata_path, "out-ice.Rds"))
df = dplyr::rbind_all(out, id = "Year")
#> Error: 'rbind_all' is not an exported object from 'namespace:dplyr'

Fix

Now dplyr offers bind_rows function to bind data-frames which should be used instead of rbind_all

extdata_path <- "https://raw.githubusercontent.com/csgillespie/efficientR/master/extdata/"
out <- readr::read_rds(paste0(extdata_path, "out-ice.Rds"))
df <- dplyr::bind_rows(out, .id = "Year")
  head(df)
#>   Year   long     lat order  hole piece id group
#> 1 1985 575000 5700000     1 FALSE     1  0   0.1
#> 2 1985 600000 5700000     2 FALSE     1  0   0.1
#> 3 1985 600000 5675000     3 FALSE     1  0   0.1
#> 4 1985 575000 5675000     4 FALSE     1  0   0.1
#> 5 1985 575000 5700000     5 FALSE     1  0   0.1
#> 6 1985 500000 5625000     1 FALSE     1  1   1.1

Please note that I am using dplyr version 1.0.8

packageVersion("dplyr")
#> [1] '1.0.8'
@shafayetShafee
Copy link
Contributor Author

@Robinlovelace, Can I make a pull request suggesting this fix 😃?

@Robinlovelace
Copy link
Collaborator

@Robinlovelace, Can I make a pull request suggesting this fix smiley?

Yes, that would be greatly appreciated. Apologies for slow response..

@shafayetShafee
Copy link
Contributor Author

@Robinlovelace, I need help with another thing, that is, which of the following approach should I follow to read the out-ice.Rds,

out = readRDS("extdata/out-ice.Rds")

which will not work for someone, who just wants to copy code from the book and run it.

Or,

extdata_path <- "https://raw.githubusercontent.com/csgillespie/efficientR/master/extdata/"
out <- readr::read_rds(paste0(extdata_path, "out-ice.Rds"))

which will require the reader to install the readr package and this should be mentioned in the prerequisites section of the 1st chapter of the book.

Thank you 😄!

@Robinlovelace
Copy link
Collaborator

I like the 2nd option better, good point!

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

No branches or pull requests

2 participants