From aa2e17631df3aba797097669b0c1b280fe87d174 Mon Sep 17 00:00:00 2001 From: bschilder Date: Fri, 20 Oct 2023 20:55:52 +0100 Subject: [PATCH] melt_finemapping_results checks is alreadu melted now --- R/is_melted.R | 3 +++ R/melt_finemapping_results.R | 8 ++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) create mode 100644 R/is_melted.R diff --git a/R/is_melted.R b/R/is_melted.R new file mode 100644 index 0000000..c9c2a69 --- /dev/null +++ b/R/is_melted.R @@ -0,0 +1,3 @@ +is_melted <- function(dat){ + all(c("Method","PP","CS") %in% names(dat)) +} \ No newline at end of file diff --git a/R/melt_finemapping_results.R b/R/melt_finemapping_results.R index e6eb028..11c9b15 100644 --- a/R/melt_finemapping_results.R +++ b/R/melt_finemapping_results.R @@ -6,7 +6,8 @@ #' @param dat Fine-mapping results data. #' @param verbose Print messages. #' -#' @return Melted \link[data.table]{data.table} +#' @returns Modified \link[data.table]{data.table} +#' with the new columns "Method","PP", and "CS". #' @export #' @importFrom data.table melt.data.table data.table #' @importFrom stats setNames @@ -14,7 +15,10 @@ #' finemap_melt <- echodata::melt_finemapping_results(dat = echodata::BST1) melt_finemapping_results <- function(dat, verbose=TRUE){ - + if(is_melted(dat)){ + messager("Data is already melted. Skipping.",v=verbose) + return(dat) + } PP_cols <- grep("\\.PP$",colnames(dat), value = TRUE) CS_cols <- grep("\\.CS$",colnames(dat), value = TRUE) messager("Melting PP and CS from",length(CS_cols),