From 0e5c7e4ee0f1ec31493fed5124a2007ff64e676f Mon Sep 17 00:00:00 2001 From: Michal Stolarczyk Date: Fri, 20 Mar 2020 09:44:38 -0400 Subject: [PATCH] implement remove; #35 --- R/constants.R | 3 ++- R/project.R | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/R/constants.R b/R/constants.R index cc3bb675..1d831d1d 100644 --- a/R/constants.R +++ b/R/constants.R @@ -12,4 +12,5 @@ CFG_IMPLY_IF_KEY = "if" CFG_DERIVE_ATTRS_KEY = "attributes" CFG_DERIVE_SOURCES_KEY = "sources" CFG_IMPORTS_KEY = "imports" -CFG_DUPLICATE_KEY = "duplicate" \ No newline at end of file +CFG_DUPLICATE_KEY = "duplicate" +CFG_REMOVE_KEY = "remove" \ No newline at end of file diff --git a/R/project.R b/R/project.R index 07fbfbb2..bf29157c 100644 --- a/R/project.R +++ b/R/project.R @@ -76,6 +76,7 @@ setMethod( ".modifySamples", signature = "Project", definition = function(object) { + object = .removeAttrs(object) object = .appendAttrs(object) object = .duplicateAttrs(object) object = .implyAttrs(object) @@ -283,6 +284,26 @@ setMethod( # sample modifiers -------------------------------------------------------- +#' Remove attributes across all the samples +#' +#' @param .Object an object of \code{\link{Project-class}} +#' +#' @return an object of \code{\link{Project-class}} +.removeAttrs <- function(.Object) { + if (!CFG_MODIFIERS_KEY %in% names(config(.Object))) return(.Object) + modifiers = config(.Object)[[CFG_MODIFIERS_KEY]] + if (!CFG_REMOVE_KEY %in% names(modifiers)) return(.Object) + toRemove = modifiers[[CFG_REMOVE_KEY]] + if (!is.null(toRemove)) { + # get a copy of samples to get the dimensions + for (rem in toRemove) { + if(rem %in% colnames(sampleTable(.Object))) { + .Object@samples[,rem] = NULL + } + } + } + return(.Object) +} #' Append constant attributes across all the samples