diff --git a/DESCRIPTION b/DESCRIPTION index dc7a6fc..42b9fd6 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -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" @@ -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, diff --git a/NEWS.md b/NEWS.md index 28d5f46..8666e13 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,9 @@ +# d3r 0.6.9 + +### Updates + +* modify `d3_nest()` to work with new tidyr. + # d3r 0.6.8 ### Updates diff --git a/R/hierarchy.R b/R/hierarchy.R index 2fd883f..39a2861 100644 --- a/R/hierarchy.R +++ b/R/hierarchy.R @@ -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" ) ) )) @@ -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" ) ) ))