From 7da62801d534bbf0cba8380a2f4e881011786fda Mon Sep 17 00:00:00 2001 From: allenzhuaz Date: Thu, 25 Aug 2022 18:33:47 -0400 Subject: [PATCH 1/2] update per CRAN reviewer's suggestions --- R/graphMCP.R | 44 ++++++++++++++--------------- R/misc.R | 12 ++------ man/gMCPLite-package.Rd | 2 +- man/placeNodes.Rd | 5 ---- man/replaceVariables.Rd | 3 -- vignettes/GraphicalMultiplicity.Rmd | 11 ++++++++ 6 files changed, 36 insertions(+), 41 deletions(-) diff --git a/R/graphMCP.R b/R/graphMCP.R index d7fff05..9860f6f 100644 --- a/R/graphMCP.R +++ b/R/graphMCP.R @@ -14,7 +14,7 @@ # # You should have received a copy of the GNU General Public License # along with this program. If not, see . - + ## Graph representation in gMCP #' Class graphMCP @@ -195,24 +195,24 @@ setMethod("print", "gMCPResult", setMethod("show", "gMCPResult", function(object) { # callNextMethod(x, ...) - cat("gMCP-Result\n") - cat("\nInitial graph:\n") + message("gMCP-Result\n") + message("\nInitial graph:\n") print(object@graphs[[1]]) - cat("\nP-values:\n") + message("\nP-values:\n") print(object@pvalues) if (length(object@adjPValues)>0) { - cat("\nAdjusted p-values:\n") + message("\nAdjusted p-values:\n") print(object@adjPValues) } - cat(paste("\nAlpha:",object@alpha,"\n")) + message(paste("\nAlpha:",object@alpha,"\n")) if (all(!object@rejected)) { - cat("\nNo hypotheses could be rejected.\n") + message("\nNo hypotheses could be rejected.\n") } else { - cat("\nHypothesis rejected:\n") + message("\nHypothesis rejected:\n") print(object@rejected) } if (length(object@graphs)>1) { - cat("\nFinal graph after", length(object@graphs)-1 ,"steps:\n") + message("\nFinal graph after", length(object@graphs)-1 ,"steps:\n") print(object@graphs[[length(object@graphs)]]) } }) @@ -414,31 +414,31 @@ setMethod("show", "graphMCP", function(object) { #callNextMethod(object) nn <- getNodes(object) - cat("A graphMCP graph\n") + message("A graphMCP graph\n") if (!isTRUE(all.equal(sum(getWeights(object)),1))) { - cat(paste("Sum of weight: ",sum(getWeights(object)),"\n", sep="")) + message(paste("Sum of weight: ",sum(getWeights(object)),"\n", sep="")) } for (node in getNodes(object)) { - cat(paste(node, " (",ifelse(nodeAttr(object, node, "rejected"),"rejected, ",""),"weight=",format(object@weights[node], digits=4, drop0trailing=TRUE),")\n", sep="")) + message(paste(node, " (",ifelse(nodeAttr(object, node, "rejected"),"rejected, ",""),"weight=",format(object@weights[node], digits=4, drop0trailing=TRUE),")\n", sep="")) } printEdge <- FALSE; for (i in getNodes(object)) { for (j in getNodes(object)) { if (object@m[i,j]!=0) { if (!printEdge) { - cat("Edges:\n") + message("Edges:\n") printEdge <- TRUE } - cat(paste(i, " -(", object@m[i,j], ")-> ", j, "\n")) + message(paste(i, " -(", object@m[i,j], ")-> ", j, "\n")) } } } - if (!printEdge) cat("No edges.\n") + if (!printEdge) message("No edges.\n") #if (!is.null(attr(object, "pvalues"))) { # TODO Do we want to have more output here? - # cat("\nAttached p-values: ", attr(object, "pvalues"), "\n") + # message("\nAttached p-values: ", attr(object, "pvalues"), "\n") #} - #cat(paste("\nalpha=",paste(format(getWeights(object), digits=4 ,drop0trailing=TRUE),collapse="+"),"=",sum(getWeights(object)),"\n", sep="")) - cat("\n") + #message(paste("\nalpha=",paste(format(getWeights(object), digits=4 ,drop0trailing=TRUE),collapse="+"),"=",sum(getWeights(object)),"\n", sep="")) + message("\n") } ) @@ -641,19 +641,19 @@ setMethod("print", "gPADInterim", setMethod("show","gPADInterim", function(object) { - cat("Pre-planned graphical MCP at level:",object@alpha,"\n") + message("Pre-planned graphical MCP at level:",object@alpha,"\n") show(object@preplanned) n <- length(object@z1) - cat("Proportion of pre-planned measurements\n collected up to interim:\n") + message("Proportion of pre-planned measurements\n collected up to interim:\n") v <- object@v if(length(v) == 1) v <- rep(v,n) names(v) <- paste('H',1:n,sep='') print(v) - cat("Z-scores computed at interim\n") + message("Z-scores computed at interim\n") z1 <- object@z1 names(z1) <- paste('H',1:n,sep='') print(z1) - cat("\n Interim PCE's by intersection\n") + message("\n Interim PCE's by intersection\n") tab <- round(cbind(object@Aj,object@BJ),3) rownames(tab) <- to.intersection(1:nrow(tab)) colnames(tab) <- c(paste('A(',1:n,')',sep=''),'BJ') diff --git a/R/misc.R b/R/misc.R index b31375c..fd71a9e 100644 --- a/R/misc.R +++ b/R/misc.R @@ -63,12 +63,12 @@ substituteEps <- function(graph, eps=10^(-3)) { # Real function: if (is.numeric(graph@m)) return(graph) m <- matrix(gsub("\\\\epsilon", eps, graph@m), nrow=length(getNodes(graph))) - options(warn=-1) + m2 <- matrix(sapply(m, function(x) { result <- try(eval(parse(text=x)), silent=TRUE); ifelse(class(result)=="try-error",NA,result) }), nrow=length(getNodes(graph))) - options(warn=0) + if (all(is.na(m)==is.na(m2))) m <- m2 rownames(m) <- colnames(m) <- getNodes(graph) graph@m <- m @@ -104,9 +104,6 @@ substituteEps <- function(graph, eps=10^(-3)) { #' @examples #' #' graph <- HungEtWang2010() -#' \dontrun{ -#' replaceVariables(graph) -#' } #' replaceVariables(graph, list("tau"=0.5,"omega"=0.5, "nu"=0.5)) #' replaceVariables(graph, list("tau"=c(0.1, 0.5, 0.9),"omega"=c(0.2, 0.8), "nu"=0.4)) #' @@ -376,11 +373,6 @@ permutations <- function(n) { #' #' g <- placeNodes(g, nrow=2, force=TRUE) #' -#' \dontrun{ -#' graphGUI(g) -#' -#' } -#' #' #' @export placeNodes placeNodes <- function(graph, nrow, ncol, byrow = TRUE, topdown = TRUE, force = FALSE) { diff --git a/man/gMCPLite-package.Rd b/man/gMCPLite-package.Rd index 3dc6f0d..f5ab279 100644 --- a/man/gMCPLite-package.Rd +++ b/man/gMCPLite-package.Rd @@ -8,7 +8,7 @@ \description{ \if{html}{\figure{logo.png}{options: style='float: right' alt='logo' width='120'}} -A lightweight fork of 'gMCP' with functions for graphical described multiple test procedures. Implement a flexible graph function using 'ggplot2' visualizations to create a multiplicity graph. Contain instructions of multiplicity graph and graphical testing for group sequential design, and necessary unit testing cases using `testthat`. +A lightweight fork of 'gMCP' with functions for graphical described multiple test procedures. Implements a flexible function using 'ggplot2' to create multiplicity graph visualizations. Contains instructions of multiplicity graph and graphical testing for group sequential design, with necessary unit testing using 'testthat'. } \seealso{ Useful links: diff --git a/man/placeNodes.Rd b/man/placeNodes.Rd index d993373..0e9de2e 100644 --- a/man/placeNodes.Rd +++ b/man/placeNodes.Rd @@ -40,11 +40,6 @@ g <- matrix2graph(matrix(0, nrow=6, ncol=6)) g <- placeNodes(g, nrow=2, force=TRUE) -\dontrun{ -graphGUI(g) - -} - } \seealso{ diff --git a/man/replaceVariables.Rd b/man/replaceVariables.Rd index 50f95aa..635f0c1 100644 --- a/man/replaceVariables.Rd +++ b/man/replaceVariables.Rd @@ -46,9 +46,6 @@ each variable replaced with the specified numeric value. \examples{ graph <- HungEtWang2010() -\dontrun{ -replaceVariables(graph) -} replaceVariables(graph, list("tau"=0.5,"omega"=0.5, "nu"=0.5)) replaceVariables(graph, list("tau"=c(0.1, 0.5, 0.9),"omega"=c(0.2, 0.8), "nu"=0.4)) diff --git a/vignettes/GraphicalMultiplicity.Rmd b/vignettes/GraphicalMultiplicity.Rmd index 5a60e35..1885bf7 100644 --- a/vignettes/GraphicalMultiplicity.Rmd +++ b/vignettes/GraphicalMultiplicity.Rmd @@ -77,6 +77,11 @@ For group sequential designs, we assume 1-sided testing. To reveal code blocks for the remainder of the document, press the code buttons indicated throughout. The initial code block sets options and loads needed packages; no modification should be required by the user. +```{r, echo=FALSE} +# obtain the user's default option +user_scipen_option <- options()$scipen +``` + ```{r, message=FALSE, warning=FALSE} ### THERE SHOULD BE NO NEED TO MODIFY THIS CODE SECTION options(scipen = 999) @@ -644,6 +649,12 @@ for (i in 1:nHypotheses) { } ``` +```{r, echo=FALSE} +# reset to the user's default option +options(user_scipen_option) +``` + + ## Session information You can use `sessionInfo()` to document the versions of R and R packages used to render this document. From 5446384e2c95513c31a13776627d6e8eee7fd717 Mon Sep 17 00:00:00 2001 From: Nan Xiao Date: Thu, 25 Aug 2022 23:17:08 -0400 Subject: [PATCH 2/2] Use reviewer suggested fix for `options()` --- vignettes/GraphicalMultiplicity.Rmd | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/vignettes/GraphicalMultiplicity.Rmd b/vignettes/GraphicalMultiplicity.Rmd index 1885bf7..fb0408f 100644 --- a/vignettes/GraphicalMultiplicity.Rmd +++ b/vignettes/GraphicalMultiplicity.Rmd @@ -77,14 +77,10 @@ For group sequential designs, we assume 1-sided testing. To reveal code blocks for the remainder of the document, press the code buttons indicated throughout. The initial code block sets options and loads needed packages; no modification should be required by the user. -```{r, echo=FALSE} -# obtain the user's default option -user_scipen_option <- options()$scipen -``` - ```{r, message=FALSE, warning=FALSE} ### THERE SHOULD BE NO NEED TO MODIFY THIS CODE SECTION -options(scipen = 999) +# Prefer fixed notation +old <- options(scipen = 999) # Colorblind palette cbPalette <- c("#999999", "#E69F00", "#56B4E9", "#009E73", "#F0E442", "#0072B2", "#D55E00", "#CC79A7") # 2 packages used for data storage and manipulation: dplyr, tibble @@ -649,12 +645,11 @@ for (i in 1:nHypotheses) { } ``` -```{r, echo=FALSE} -# reset to the user's default option -options(user_scipen_option) +```{r} +# Restore default options +options(old) ``` - ## Session information You can use `sessionInfo()` to document the versions of R and R packages used to render this document.