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

Fix .id arg missing in imap_dfr #454

Merged
merged 5 commits into from
Feb 5, 2018
Merged

Conversation

cderv
Copy link
Contributor

@cderv cderv commented Feb 5, 2018

This is a small PR that fixes #429

  • .id argument in imap_dfr is now took into account (see reprex below)

  • unused .id argument in imap_dfc is now suppressed

  • Verifying if it was all, I found that in flatten_df* verbs there was no check if dplyr is installed or not as in map_df*, map2_df*, and pmap_df*. As it is small changes, I have included in this PR rather than opening a new one

Checking the fix

library(purrr)
as_tibble_custom <- function(value, name = NULL) {
  tab <- tibble::as_tibble(value)
  if (! is.null(name)) {
    tab$col_id = paste0("col_", name)
  }
  tab
}
# with imap it does not work
list(a = 1, b = 2, c = 3) %>%
  imap_dfr(as_tibble_custom)
#> # A tibble: 3 x 2
#>   value col_id
#>   <dbl> <chr> 
#> 1  1.00 col_a 
#> 2  2.00 col_b 
#> 3  3.00 col_c
list(a = 1, b = 2, c = 3) %>%
  imap_dfr(as_tibble_custom, .id = "name")
#> # A tibble: 3 x 3
#>   name  value col_id
#>   <chr> <dbl> <chr> 
#> 1 a      1.00 col_a 
#> 2 b      2.00 col_b 
#> 3 c      3.00 col_c

NEWS.md Outdated
@@ -1,6 +1,10 @@

# purrr 0.2.4.9000

* `flatten_dfr` and `flatten_dfc` now aborts if `dplyr` is not installed. (#454)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

House style is to not put package names in back ticks, and to put () after function names. Can you please change?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh sorry for that. I will definitely remember that for next time.
And revise the tidyverse style guide.
Correction is done.

@hadley hadley merged commit f7010b7 into tidyverse:master Feb 5, 2018
@cderv cderv deleted the fix-id-arg branch February 5, 2018 14:45
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 this pull request may close these issues.

.id argument ignored in imap_dfr()/imap_dfc()?
2 participants