Skip to content

Commit

Permalink
fix #15
Browse files Browse the repository at this point in the history
use tibble::enframe() to convert named vectors to empty tibble in list_NA()
  • Loading branch information
mps9506 committed Apr 1, 2020
1 parent e0e509e commit cc4369f
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 10 deletions.
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,6 @@ importFrom(stats,sd)
importFrom(stats,var)
importFrom(tibble,as.tibble)
importFrom(tibble,as_tibble)
importFrom(tibble,enframe)
importFrom(tidyr,pivot_wider)
importFrom(tidyr,unnest)
6 changes: 4 additions & 2 deletions R/tbr_gmean.R
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,13 @@ tbr_gmean_window <- function(x, tcolumn, unit = "years", n, i, ...) {
dots <- list(...)

if (is.na(dots$conf)) {
resultsColumns <- c("mean")
resultsColumns <- c("mean" = NA)
}

else {
resultsColumns <- c("mean", "lwr_ci", "upr_ci")
resultsColumns <- c("mean" = NA,
"lwr_ci" = NA,
"upr_ci" = NA)
}

# do not calculate the first row, always returns NA
Expand Down
23 changes: 15 additions & 8 deletions R/utils.R
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@

# function to return tibble with NAs as specified
# list_NA(c("mean", "lwr.ci", "upr.ci"))
list_NA <- function(...) {
names <- c(...)
results <- as.list(c(rep(NA, length(names))))
names(results) <- names
results <- tibble::as_tibble(results)
results[1:length(results)] <- as.numeric(results[1:length(results)])
#' List NA
#'
#' function to return tibble with NAs as specified
#' @param x named vector
#'
#' @importFrom tibble enframe
#' @importFrom tidyr pivot_wider
#' @return empty tibble
#' @keywords internal
list_NA <- function(x) {
names <- x

results <- tibble::enframe(names) %>%
mutate(value = as.numeric(.data$value)) %>%
tidyr::pivot_wider()
return(results)
}

Expand Down
18 changes: 18 additions & 0 deletions man/list_NA.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions tbrf.Rproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ LaTeX: pdfLaTeX
BuildType: Package
PackageUseDevtools: Yes
PackageInstallArgs: --no-multiarch --with-keep.source
PackageCheckArgs: --as-cran
PackageRoxygenize: rd,collate,namespace,vignette

0 comments on commit cc4369f

Please sign in to comment.