R/create_table_ep_15.R

Defines functions create_table_ep_15

Documented in create_table_ep_15

utils::globalVariables(c("value"))

#' Create table for precision calculations
#' @importFrom dplyr filter
#' @importFrom tidyr pivot_longer
#' @importFrom utils data
#'
#' @param data a long or a wider data.frame with the same structure of CLSIEP15::ferritin_long or CLSIEP15::ferritin_wider
#' @param data_type c('wider', 'long')
#'
#' @return a data.frame with renamed columns and structure adjustments
#' @export
#'
#' @examples data <- create_table_ep_15(ferritin_long, data_type = "longer")
create_table_ep_15 <- function(data, data_type = 'wider'){

  if(data_type == 'wider'){
    colnames(data) <- c('rep', paste0('Run_', 1:(ncol(data)-1)))

    pivoted <-
      data |>
      pivot_longer(cols = -rep) |>
      dplyr::filter(!is.na(`value`))

    return(pivoted)
  }else if(data_type == 'long'){
    colnames(data) <- c('rep', 'name', 'value')

    return(data)
  }
}

Try the CLSIEP15 package in your browser

Any scripts or data that you put into this service are public.

CLSIEP15 documentation built on Nov. 11, 2023, 1:08 a.m.