Skip to content

Commit

Permalink
play nicely with tidyr 0.7.0
Browse files Browse the repository at this point in the history
  • Loading branch information
timelyportfolio committed Aug 21, 2017
1 parent e95a563 commit e376478
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
6 changes: 3 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Package: d3r
Type: Package
Title: 'd3.js' Utilities for R
Version: 0.6.8
Date: 2017-08-07
Version: 0.6.9
Date: 2017-08-20
Authors@R: c(
person(
"Mike", "Bostock"
Expand Down Expand Up @@ -38,7 +38,7 @@ License: BSD_3_clause + file LICENSE
Encoding: UTF-8
Imports: dplyr,
htmltools,
tidyr
tidyr (>= 0.7.0)
Suggests: jsonlite,
listviewer,
purrr,
Expand Down
6 changes: 6 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# d3r 0.6.9

### Updates

* modify `d3_nest()` to work with new tidyr.

# d3r 0.6.8

### Updates
Expand Down
15 changes: 9 additions & 6 deletions R/hierarchy.R
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,18 @@ d3_nest <- function(
stopifnot(!is.null(data), inherits(data, "data.frame"))
nonnest_cols <- dplyr::setdiff(colnames(data),value_cols)

# looks like new tidyr requires tibble to nest correctly
data <- dplyr::as_tibble(data)

# convert factor to character
data <- dplyr::mutate_if(data, is.factor, as.character)

data_nested <- dplyr::bind_rows(promote_na(
change_to_name(
tidyr::nest_(
tidyr::nest(
data=data,
nest_cols=c(nonnest_cols[length(nonnest_cols)], value_cols),
key_col="children"
dplyr::one_of(c(nonnest_cols[length(nonnest_cols)], value_cols)),
.key="children"
)
)
))
Expand All @@ -102,10 +105,10 @@ d3_nest <- function(
)){
data_nested <- dplyr::bind_rows(promote_na(
change_to_name(
tidyr::nest_(
tidyr::nest(
data_nested,
nest_cols = colnames(data_nested)[colnames(data_nested) %in% c(x,"children",value_cols)],
key_col = "children"
dplyr::one_of(colnames(data_nested)[colnames(data_nested) %in% c(x,"children",value_cols)]),
.key = "children"
)
)
))
Expand Down

0 comments on commit e376478

Please sign in to comment.