diff --git a/DESCRIPTION b/DESCRIPTION index 7da8e9d..2906e60 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: tidync Title: A Tidy Approach to 'NetCDF' Data Exploration and Extraction -Version: 0.3.0.9002 +Version: 0.4.0 Authors@R: c(person("Michael", "Sumner", email = "mdsumner@gmail.com", role = c("aut", "cre")), person("Simon", "Wotherspoon", role = "ctb"), person("Tomas", "Remenyi", role = "ctb"), @@ -9,7 +9,8 @@ Authors@R: c(person("Michael", "Sumner", email = "mdsumner@gmail.com", role = c( person("Tim", "Lucas", role = "ctb"), person("Hadley", "Wickham", role = "ctb"), person("Adrian", "Odenweller", role = "ctb"), - person("Patrick", "Van Laake", role = "ctb")) + person("Patrick", "Van Laake", role = "ctb"), + person("Fabian", "Bernhard", role = "ctb")) Description: Tidy tools for 'NetCDF' data sources. Explore the contents of a 'NetCDF' source (file or URL) presented as variables organized by grid with a database-like interface. The hyper_filter() interactive function translates the @@ -31,8 +32,8 @@ Imports: rlang, tibble, tidyr, - CFtime (>= 1.2.0) -RoxygenNote: 7.2.3 + CFtime (>= 1.4.0) +RoxygenNote: 7.3.2 Suggests: ggplot2, knitr, rmarkdown, diff --git a/R/hyper_tibble.R b/R/hyper_tibble.R index 0730fa4..2c4be2f 100644 --- a/R/hyper_tibble.R +++ b/R/hyper_tibble.R @@ -59,12 +59,20 @@ hyper_tibble.tidync<- function(x, ..., na.rm = TRUE, force = FALSE) { out <- tibble::as_tibble(lapply(slabs, as.vector)) prod_dims <- 1 - dn <- dimnames(slabs[[1]]) - nm <- names(dn) + trans <- attr(slabs, "transforms") - for (i in seq_along(nm)) { - out[[nm[i]]] <- rep(dn[[i]], each = prod_dims, length.out = total_prod) - prod_dims <- prod_dims * length(dn[[i]]) + for (i in seq_along(trans)) { + nm <- names(trans)[i] + nr <- sum(trans[[i]]$selected) + + out[[nm]] <- if ("timestamp" %in% colnames(trans[[i]])) + rep(dplyr::filter(trans[[nm]], .data$selected)[["timestamp"]], + each = prod_dims, length.out = total_prod) + else + rep(dplyr::filter(trans[[nm]], .data$selected)[[nm]], + each = prod_dims, length.out = total_prod) + + prod_dims <- prod_dims * nr } if (na.rm) out <- dplyr::filter(out, !all_na) out