From d2fbd5403821aa86ca203d2e8cfca28464378f69 Mon Sep 17 00:00:00 2001 From: Jitao David Zhang Date: Thu, 12 Feb 2026 22:23:11 +0100 Subject: [PATCH 1/3] updating ribiosPlot to plan for CRAN submission --- .gitignore | 2 + DESCRIPTION | 2 +- NAMESPACE | 6 +- R/colors.R | 2 +- R/plotVenn.R | 137 ++++++++++++++++++++++++++++---------- R/ribiosPlot-package.R | 14 +--- R/utils.R | 3 +- cran-comments.md | 23 ++----- man/colorpanel.Rd | 2 +- man/plotVenn.Rd | 22 +++--- man/ribiosPlot-package.Rd | 18 +++-- 11 files changed, 143 insertions(+), 88 deletions(-) diff --git a/.gitignore b/.gitignore index 74709ac..f154f95 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,5 @@ inst/doc .Rhistory .RDatat *.swp +*.Rcheck +*.tar.gz diff --git a/DESCRIPTION b/DESCRIPTION index cf25af2..0e45487 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -21,7 +21,6 @@ Imports: RColorBrewer, grid, gridExtra, - utils, graphics, ribiosUtils, stats, @@ -67,3 +66,4 @@ LazyLoad: yes Encoding: UTF-8 RoxygenNote: 7.3.3 VignetteBuilder: knitr +Additional_repositories: https://bedapub.r-universe.dev diff --git a/NAMESPACE b/NAMESPACE index 0222bce..d43cf90 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -127,12 +127,9 @@ importFrom(graphics,abline) importFrom(graphics,legend) importFrom(graphics,panel.smooth) importFrom(grid,gpar) -importFrom(grid,grid.layout) +importFrom(grid,grid.newpage) importFrom(grid,grid.text) -importFrom(grid,plotViewport) -importFrom(grid,pushViewport) importFrom(grid,unit) -importFrom(grid,viewport) importFrom(lattice,panel.xyplot) importFrom(ribiosUtils,assertFile) importFrom(ribiosUtils,basefilename) @@ -145,4 +142,3 @@ importFrom(ribiosUtils,isOdd) importFrom(ribiosUtils,mmatch) importFrom(stats,cor) importFrom(stats,lm) -importFrom(utils,assignInNamespace) diff --git a/R/colors.R b/R/colors.R index 192ae48..5e2173b 100644 --- a/R/colors.R +++ b/R/colors.R @@ -8,7 +8,7 @@ #' #' The values for \sQuote{low, mid, high} can be given as color names #' (\sQuote{red}), plot color index (\code{2}=red), and HTML-style RGB, -#' (\dQuote{\#FF0000}=red). +#' (\dQuote{#FF0000}=red). #' #' If \sQuote{mid} is supplied, then the returned color panel will consist of #' \sQuote{n - floor(n/2)} HTML-style RGB elements which vary smoothly between diff --git a/R/plotVenn.R b/R/plotVenn.R index f011c6a..a3092d4 100644 --- a/R/plotVenn.R +++ b/R/plotVenn.R @@ -1,45 +1,114 @@ -makevp.eqsc.mod <- function (xrange, yrange) { - pushViewport(plotViewport(name = "Vennmar", c(1.5, 1, 3, 1))) - pushViewport(viewport(name = "Vennlay", layout = grid.layout(1, - 1, widths = diff(xrange), heights = diff(yrange), respect = TRUE))) - pushViewport(viewport(name = "Vennvp", layout.pos.row = 1, - layout.pos.col = 1, xscale = xrange, yscale = yrange)) -} +## Venn diagram plotting adapted from Vennerable package +## (js229/Vennerable, GPL license) +## Custom margins c(1.5, 1, 3, 1) are used instead of the default c(1, 1, 1, 1) -replaceFunc <- function(funcName, - newFunc, package) { - env.name <- paste("package", package, sep=":") - env <- as.environment(env.name) - unlockBinding(funcName, env) - assignInNamespace(funcName, newFunc, ns=package, envir=env) - assign(funcName, newFunc, envir=env) - lockBinding(funcName, env) +## Local helper adapted from Vennerable (unexported PlotSetLabels) +.plotSetLabels <- function(object, gp) { + VLabels <- Vennerable::VennGetSetLabels(object) + if (nrow(VLabels) == 0) { + warning("Can't show Set labels") + return(invisible(NULL)) + } + hj <- sapply(VLabels$hjust, function(x) { + switch(x, left = 0, right = 1, center = , centre = 0.5) + }) + vj <- sapply(VLabels$vjust, function(x) { + switch(x, top = 1, bottom = 0, center = , centre = 0.5) + }) + for (i in seq_len(nrow(VLabels))) { + grid.text( + x = VLabels$x[i], y = VLabels$y[i], + hjust = hj[i], vjust = vj[i], gp = gp[[i]], + label = as.character(VLabels$Label[i]), + default.units = "native" + ) + } } #' Plot Venn object of the Vennerable package -#' -#' The function plots Venn object of the Vennerable package in a way that -#' better suits my eyes -#' -#' +#' +#' The function plots Venn objects from the Vennerable package with +#' custom margins that better suit publication figures. +#' #' @param venn Venn object from the Vennerable package #' @param main Figure title -#' @param show default options -#' @param ... other parameters passed to plotVenn -#' @return Side effect is used - a plot is generated -#' @note The function is applicable to Vennerable package version 3.0. +#' @param show Named list controlling which elements to display. +#' Supported elements: \code{Universe} (logical), \code{Sets} (logical), +#' \code{SetLabels} (logical), \code{DarkMatter} (logical), +#' \code{Faces} (logical), \code{FaceText} (character, e.g. \code{"weight"}). +#' @param ... Other parameters passed to \code{Vennerable::compute.Venn} +#' @return Side effect is used - a plot is generated. +#' @note The function requires Vennerable package version 3.0 or later. +#' Plotting logic adapted from Vennerable (GPL license). #' @examples -#' -#' if(require("Vennerable")) { -#' myVenn <- list(A=LETTERS[1:24], B=LETTERS[3:8], C=LETTERS[5:9]) -#' plotVenn(Venn(myVenn), main="Letters") +#' +#' if (requireNamespace("Vennerable", quietly = TRUE)) { +#' myVenn <- list(A = LETTERS[1:24], B = LETTERS[3:8], C = LETTERS[5:9]) +#' plotVenn(Vennerable::Venn(myVenn), main = "Letters") #' } -#' +#' #' @export plotVenn plotVenn <- function(venn, - main="", - show=list(FaceText="weight", Universe=FALSE),...) { - replaceFunc("makevp.eqsc", makevp.eqsc.mod, package="Vennerable") - Vennerable:::plotVenn(venn, show=show,...) - grid.text(main, y=unit(0.95, "npc"), gp=gpar(fontsize=16, font=2)) + main = "", + show = list(FaceText = "weight", Universe = FALSE), + ...) { + if (!requireNamespace("Vennerable", quietly = TRUE)) { + stop("Package 'Vennerable' is required but not installed.") + } + + C3 <- Vennerable::compute.Venn(venn, ...) + + ## Merge show parameters with defaults + show.default <- list( + Universe = FALSE, Sets = TRUE, SetLabels = TRUE, + DarkMatter = FALSE, Faces = TRUE, FaceText = "weight" + ) + show.default[names(show)] <- show + + ## Get graphical parameters + gp <- Vennerable::VennThemes(drawing = C3) + + ## Set up viewports with custom margins + grid.newpage() + ranges <- Vennerable::VennGetUniverseRange(C3) + xrange <- ranges[, 1] + yrange <- ranges[, 2] + grid::pushViewport(grid::plotViewport( + name = "Vennmar", margins = c(1.5, 1, 3, 1) + )) + grid::pushViewport(grid::viewport( + name = "Vennlay", + layout = grid::grid.layout(1, 1, + widths = diff(xrange), heights = diff(yrange), respect = TRUE + ) + )) + grid::pushViewport(grid::viewport( + name = "Vennvp", layout.pos.row = 1, layout.pos.col = 1, + xscale = xrange, yscale = yrange + )) + + ## Draw Venn elements + if (show.default$Faces) { + Vennerable::PlotFaces(C3, gp = gp[["Face"]]) + } + if (show.default$Sets) { + Vennerable::PlotSetBoundaries(C3, gp = gp[["Set"]]) + } + if (show.default$SetLabels) { + .plotSetLabels(C3, gp = gp[["SetText"]]) + } + if (length(show.default$FaceText) > 0) { + Vennerable::PlotIntersectionText( + C3, + element.plot = show.default$FaceText, + gp = gp[["FaceText"]], + show.dark.matter = show.default$DarkMatter + ) + } + + ## Pop viewports + grid::upViewport(3) + + ## Draw title + grid.text(main, y = unit(0.95, "npc"), gp = gpar(fontsize = 16, font = 2)) } diff --git a/R/ribiosPlot-package.R b/R/ribiosPlot-package.R index 6fd6da3..eb8e213 100644 --- a/R/ribiosPlot-package.R +++ b/R/ribiosPlot-package.R @@ -1,15 +1,5 @@ -#' ribiosPlot: Data transformation and visualization in ribios -#' -#' The package provides data structures and functions to plot graphics in the -#' ribios software suite It is a collection of code snippets I used to generate -#' plots to visualize omics data. -#' -#' @name ribiosPlot-package -#' @aliases ribiosPlot-package ribiosPlot -#' @docType package -#' @author Jitao David Zhang -#' @keywords package -NULL +#' @keywords internal +"_PACKAGE" #' @export ribiosUtils::boundNorm diff --git a/R/utils.R b/R/utils.R index c21b2a2..450754a 100644 --- a/R/utils.R +++ b/R/utils.R @@ -1,9 +1,8 @@ #' @importFrom grDevices blues9 col2rgb colorRampPalette #' @importFrom grDevices dev.print gray palette pdf rgb xy.coords -#' @importFrom utils assignInNamespace #' @importFrom ribiosUtils assertFile basefilename haltifnot #' @importFrom RColorBrewer brewer.pal brewer.pal.info -#' @importFrom grid grid.layout grid.text plotViewport pushViewport unit viewport gpar +#' @importFrom grid grid.newpage grid.text unit gpar #' @importFrom lattice panel.xyplot #' @import ggplot2 #' @import graphics diff --git a/cran-comments.md b/cran-comments.md index 0ab913a..5614db0 100644 --- a/cran-comments.md +++ b/cran-comments.md @@ -8,25 +8,16 @@ ## R CMD check results -0 errors | 0 warnings | 3 notes +0 errors | 0 warnings | 2 notes ### Notes explanation -1. **Suggests or Enhances not in mainstream repositories: ribiosArg, Vennerable** - - ribiosArg will be submitted to CRAN after ribiosUtils is accepted - - Vennerable is not on CRAN (maintained on GitHub) - -2. **Unavailable namespace imported from by a ':::' call: 'Vennerable'** - The package enhances Vennerable (not on CRAN) with a modified Venn diagram - plotting function. This functionality is optional and protected by - `if(require("Vennerable"))`. Users who don't have Vennerable installed - will simply not have access to this single function. - -3. **Possibly unsafe calls: unlockBinding, assignInNamespace** - These calls are used solely within the optional `plotVenn()` function to - patch a layout issue in the Vennerable package. The function is only - called when Vennerable is available and the user explicitly requests - Venn diagram plotting. +1. **New submission** + +2. **Suggests or Enhances not in mainstream repositories: ribiosArg, Vennerable** + - ribiosArg is available from https://bedapub.r-universe.dev + (listed in Additional_repositories) + - Vennerable is maintained on GitHub (not on CRAN) ## Notes for CRAN reviewers diff --git a/man/colorpanel.Rd b/man/colorpanel.Rd index e9aac37..ac8573f 100644 --- a/man/colorpanel.Rd +++ b/man/colorpanel.Rd @@ -25,7 +25,7 @@ See NOTES below) \details{ The values for \sQuote{low, mid, high} can be given as color names (\sQuote{red}), plot color index (\code{2}=red), and HTML-style RGB, -(\dQuote{\#FF0000}=red). +(\dQuote{#FF0000}=red). If \sQuote{mid} is supplied, then the returned color panel will consist of \sQuote{n - floor(n/2)} HTML-style RGB elements which vary smoothly between diff --git a/man/plotVenn.Rd b/man/plotVenn.Rd index af04923..286c11f 100644 --- a/man/plotVenn.Rd +++ b/man/plotVenn.Rd @@ -16,25 +16,29 @@ plotVenn( \item{main}{Figure title} -\item{show}{default options} +\item{show}{Named list controlling which elements to display. +Supported elements: \code{Universe} (logical), \code{Sets} (logical), +\code{SetLabels} (logical), \code{DarkMatter} (logical), +\code{Faces} (logical), \code{FaceText} (character, e.g. \code{"weight"}).} -\item{...}{other parameters passed to plotVenn} +\item{...}{Other parameters passed to \code{Vennerable::compute.Venn}} } \value{ -Side effect is used - a plot is generated +Side effect is used - a plot is generated. } \description{ -The function plots Venn object of the Vennerable package in a way that -better suits my eyes +The function plots Venn objects from the Vennerable package with +custom margins that better suit publication figures. } \note{ -The function is applicable to Vennerable package version 3.0. +The function requires Vennerable package version 3.0 or later. + Plotting logic adapted from Vennerable (GPL license). } \examples{ -if(require("Vennerable")) { - myVenn <- list(A=LETTERS[1:24], B=LETTERS[3:8], C=LETTERS[5:9]) - plotVenn(Venn(myVenn), main="Letters") +if (requireNamespace("Vennerable", quietly = TRUE)) { + myVenn <- list(A = LETTERS[1:24], B = LETTERS[3:8], C = LETTERS[5:9]) + plotVenn(Vennerable::Venn(myVenn), main = "Letters") } } diff --git a/man/ribiosPlot-package.Rd b/man/ribiosPlot-package.Rd index 0e10b34..e850ae6 100644 --- a/man/ribiosPlot-package.Rd +++ b/man/ribiosPlot-package.Rd @@ -2,13 +2,11 @@ % Please edit documentation in R/ribiosPlot-package.R \docType{package} \name{ribiosPlot-package} -\alias{ribiosPlot-package} \alias{ribiosPlot} -\title{ribiosPlot: Data transformation and visualization in ribios} +\alias{ribiosPlot-package} +\title{ribiosPlot: Plotting Module of Ribios for Visualization} \description{ -The package provides data structures and functions to plot graphics in the -ribios software suite It is a collection of code snippets I used to generate -plots to visualize omics data. +Provides data structures and functions for data transformation and visualization in computational biology. Includes heatmaps, color schemes, PCA plots, and various plotting utilities for drug discovery. } \seealso{ Useful links: @@ -19,6 +17,12 @@ Useful links: } \author{ -Jitao David Zhang +\strong{Maintainer}: Jitao David Zhang \email{jitao_david.zhang@roche.com} (\href{https://orcid.org/0000-0002-3085-0909}{ORCID}) [contributor] + +Other contributors: +\itemize{ + \item F.Hoffmann-La Roche AG [copyright holder] +} + } -\keyword{package} +\keyword{internal} From a4d97b4dd6ab48df0ba365dddef9dc070319758e Mon Sep 17 00:00:00 2001 From: Jitao David Zhang Date: Thu, 12 Feb 2026 22:27:45 +0100 Subject: [PATCH 2/3] updating description --- DESCRIPTION | 9 +++------ man/ribiosPlot-package.Rd | 9 ++------- 2 files changed, 5 insertions(+), 13 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 0e45487..86a55a1 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: ribiosPlot Type: Package -Title: Plotting Module of Ribios for Visualization +Title: Plotting Module of the 'ribios' Software Suite Version: 1.3.0 Date: 2026-01-24 Authors@R: @@ -8,11 +8,8 @@ Authors@R: family = "Zhang", role = c("aut", "cre", "ctb"), email = "jitao_david.zhang@roche.com", - comment = c(ORCID="0000-0002-3085-0909")), - person("F.Hoffmann-La Roche AG", role="cph")) -Description: Provides data structures and functions for data transformation - and visualization in computational biology. Includes heatmaps, color - schemes, PCA plots, and various plotting utilities for drug discovery. + comment = c(ORCID="0000-0002-3085-0909"))) +Description: Provides data structures and functions for data transformation and visualization in computational biology in drug discovery. Includes heatmaps, color schemes, PCA plots, and various plotting utilities. Depends: R (>= 3.4.0) Imports: diff --git a/man/ribiosPlot-package.Rd b/man/ribiosPlot-package.Rd index e850ae6..e4c01a2 100644 --- a/man/ribiosPlot-package.Rd +++ b/man/ribiosPlot-package.Rd @@ -4,9 +4,9 @@ \name{ribiosPlot-package} \alias{ribiosPlot} \alias{ribiosPlot-package} -\title{ribiosPlot: Plotting Module of Ribios for Visualization} +\title{ribiosPlot: Plotting Module of the 'ribios' Software Suite} \description{ -Provides data structures and functions for data transformation and visualization in computational biology. Includes heatmaps, color schemes, PCA plots, and various plotting utilities for drug discovery. +Provides data structures and functions for data transformation and visualization in computational biology in drug discovery. Includes heatmaps, color schemes, PCA plots, and various plotting utilities. } \seealso{ Useful links: @@ -19,10 +19,5 @@ Useful links: \author{ \strong{Maintainer}: Jitao David Zhang \email{jitao_david.zhang@roche.com} (\href{https://orcid.org/0000-0002-3085-0909}{ORCID}) [contributor] -Other contributors: -\itemize{ - \item F.Hoffmann-La Roche AG [copyright holder] -} - } \keyword{internal} From 4ecd1e841967bc016e53ac7d1e71c89463340074 Mon Sep 17 00:00:00 2001 From: Jitao David Zhang Date: Fri, 13 Feb 2026 08:16:38 +0100 Subject: [PATCH 3/3] make ready for CRAN submission --- R/PCAScoreMatrix.R | 5 +++-- R/cascadePlot.R | 1 + R/colors.R | 13 ++++++------- R/compactTrellis.R | 24 ++++++++++++++---------- R/expVar.R | 4 ++++ R/fcol.R | 2 ++ R/hist.R | 7 +++---- R/pairs.R | 10 +++++++--- R/pcaPlots.R | 17 ++++++++++++----- R/utils.R | 4 +++- man/brewer.pal.factor.Rd | 3 +-- man/cascadeOrder.Rd | 3 +++ man/compactPar.Rd | 4 ++++ man/expVarLabel.Rd | 4 ++++ man/getExpVarLabel.Rd | 4 ++++ man/histMat.Rd | 4 ++++ man/midCol.Rd | 6 +++--- man/panel.cor.Rd | 4 ++++ man/panel.lmSmooth.Rd | 4 ++++ man/pcaScores.Rd | 3 +++ man/pcaScoresFromLogFC.Rd | 4 ++++ man/plotPCA.Rd | 3 +++ man/plotPCAloading.Rd | 3 +++ man/print.PCAScoreMatrix.Rd | 2 +- man/print.fcol.Rd | 3 +++ man/qBreaks.Rd | 5 +---- man/setCompactTrellis.Rd | 11 +++++++---- man/squareLayout.Rd | 2 +- 28 files changed, 112 insertions(+), 47 deletions(-) diff --git a/R/PCAScoreMatrix.R b/R/PCAScoreMatrix.R index 62b9014..63c9c28 100644 --- a/R/PCAScoreMatrix.R +++ b/R/PCAScoreMatrix.R @@ -95,7 +95,7 @@ as.data.frame.PCAScoreMatrix <- function(x, #' #' @param x A \code{PCAScoreMatrix} S3-object #' @param ... Ignored -#' @return NULL, side effect is used +#' @return The input \code{x}, invisibly. #' @examples #' #' myPCmat <- PCAScoreMatrix(matrix(rnorm(15),ncol=3), c(0.25, 0.15, 0.1)) @@ -112,5 +112,6 @@ print.PCAScoreMatrix <- function(x, ...) { cat("Options\n") cat("-- Use 'as.matrix' to turn this object into a simple matrix\n") cat("-- Use 'expVar' to extract explained variances\n") - cat("-- Use 'expVarLabel' to generate labels of explained variances") + cat("-- Use 'expVarLabel' to generate labels of explained variances\n") + invisible(x) } diff --git a/R/cascadePlot.R b/R/cascadePlot.R index 614cc68..f679c75 100644 --- a/R/cascadePlot.R +++ b/R/cascadePlot.R @@ -120,6 +120,7 @@ nonNegCascadeOrder <- function(matrix) { #' zlim=c(-4,4), col="royalbluered", #' main="Cascade order") #' +#' @return An integer vector of row indices in cascade order. #' @export cascadeOrder cascadeOrder <- function(matrix, dichotomy=c('maxabs', 'mean', 'median')) { dichotomy <- match.arg(dichotomy) diff --git a/R/colors.R b/R/colors.R index 5e2173b..0c6f68b 100644 --- a/R/colors.R +++ b/R/colors.R @@ -136,14 +136,13 @@ brewer.pal.factorLevels <- function(factor, name="Greys") { #' @author Jitao David Zhang #' @examples #' -#' \dontrun{ +#' \donttest{ #' myFac <- factor(c("HSV", "BVB", "FCB", "HSV", "BVB", "HSV")) #' brewer.pal.factor(myFac, name="Set1") -#' brewer.pal.factorLevels(myFac, name="Set1") -#' +#' #' myLongFac <- factor(paste("Sample", 1:20)) #' brewer.pal.factor(myLongFac, name="Set1") -#' +#' #' myShortFac <- factor(paste("Sample", 1:2)) #' brewer.pal.factor(myShortFac, name="Set1") #' } @@ -387,13 +386,13 @@ display.threecolor.panels <- function (nc=20) { #' #' midCol("black", "red") #' midCol(c("black", "red")) -#' \dontrun{ +#' \donttest{ #' set.seed(1778) #' nCol <- 20 #' candCol <- grep("gr[a|e]y", colors(), value=TRUE, invert=TRUE) #' firstCols <- sample(candCol, nCol) #' secondCols <- rev(sample(candCol, nCol)) -#' midCols <- sapply(seq(along=firstCols), function(i) +#' midCols <- sapply(seq(along=firstCols), function(i) #' midCol(firstCols[i], secondCols[i])) #' plot.new() #' plot.window(xaxt="n", yaxt="n", xlim=c(0, nCol), @@ -401,7 +400,7 @@ display.threecolor.panels <- function (nc=20) { #' title("Example of midCol") #' segments(x0=1:nCol, y0=0, x1=1:nCol, y1=4, col="lightgray") #' points(x=rep(1:nCol, each=3), -#' y=rep(1:3, nCol), +#' y=rep(1:3, nCol), #' pch=21, cex=1.75, #' bg=as.vector(rbind(firstCols, midCols, secondCols))) #' text(0, c(1.5, 2.5, 3.5), c("Second", "Midpoint", "First"), diff --git a/R/compactTrellis.R b/R/compactTrellis.R index 84aeeee..b435625 100644 --- a/R/compactTrellis.R +++ b/R/compactTrellis.R @@ -28,19 +28,23 @@ compactTrellis <- function() { } #' Set compact trellis as default -#' -#' The function sets compact trellis options as default -#' -#' -#' @return as \code{lattice.options}. The side-effect is used. +#' +#' The function sets compact trellis options as default. +#' The previous \code{lattice.options} are saved and restored +#' via \code{on.exit} when the calling function exits. +#' +#' @return Invisibly, the previous value of the \code{default.theme} +#' lattice option, so it can be restored manually if needed. #' @examples -#' -#' \dontrun{ -#' setCompactTrellis() +#' +#' \donttest{ +#' old <- setCompactTrellis() #' } -#' +#' #' @export setCompactTrellis setCompactTrellis <- function() { - lattice::lattice.options("default.theme"=compactTrellis()) + old <- lattice::lattice.options("default.theme") + lattice::lattice.options("default.theme" = compactTrellis()) + invisible(old) } diff --git a/R/expVar.R b/R/expVar.R index 9282716..414bbc1 100644 --- a/R/expVar.R +++ b/R/expVar.R @@ -62,6 +62,8 @@ expVar.PCAScoreMatrix <- function(x, choices) { #' @param x \code{prcomp} or \code{PCAScoreMatrix} Object #' @param choices Integer indices of which PCs to be returned #' @param compact Logical, whether a compact format is returned, see example +#' @return A character vector of labels describing the explained variance +#' of each principal component. #' @export expVarLabel expVarLabel <- function(x, choices, compact) UseMethod("expVarLabel") @@ -75,6 +77,8 @@ expVarLabel <- function(x, choices, compact) UseMethod("expVarLabel") #' \code{NULL} or \code{NA} or missing, all elements are returned. #' @param compact Logical, either a \code{compact} label is returned, see #' examples. +#' @return A character vector of labels in the form +#' \code{"Principal component N (X\% variance explained)"}. #' @export getExpVarLabel <- function(ev, choices, compact=FALSE) { if(missing(choices) || is.null(choices) || (length(choices)==1 && is.na(choices))) diff --git a/R/fcol.R b/R/fcol.R index 1f89ab6..2b9f929 100644 --- a/R/fcol.R +++ b/R/fcol.R @@ -29,6 +29,7 @@ fcbase <- function(fcol) { #' Print a fcol object #' @param x A fcol object, likely constructed by \code{\link{fcol}} #' @param ... Not used now +#' @return The input \code{x}, invisibly. #' @examples #' fc <- fcol(c("lightblue", "orange", "lightblue"), base=c("orange", "lightblue")) #' fc @@ -41,6 +42,7 @@ print.fcol <- function(x, ...) { "Colors: (", length(acol), "):", ribiosUtils::chosenFew(acol),"\n", "Base colors (", length(bcol), "):", ribiosUtils::chosenFew(fcbase(x)), "\n", sep="") + invisible(x) } #' Replace base colors of a fcol object with a different value diff --git a/R/hist.R b/R/hist.R index 7ee43d1..93058af 100644 --- a/R/hist.R +++ b/R/hist.R @@ -60,11 +60,8 @@ qHist <- function(x,quantiles=0.25, breaks=100, #' @seealso This function is directly used by \code{qHist} #' @examples #' -#' \dontrun{ #' testVal <- rnorm(1000) -#' qBreaks(testVal, quantiles=c(0.25, 0.75), breaks=100) ## should be about -#' 400 -#' } +#' qBreaks(testVal, quantiles=c(0.25, 0.75), breaks=100) #' #' @export qBreaks <- function(x,quantiles=c(0,0.99), breaks=100) { @@ -143,6 +140,8 @@ xclipHist <- function(x, xclip=c(0.01, 0.99), breaks=100, #' testMat <- matrix(rnorm(1000), nrow=100) #' histMat(testMat) #' +#' @return Invisibly, a list as returned by \code{\link{hist}}, with +#' additional elements \code{xlim} and \code{linesOpt}. #' @export histMat histMat <- function(mat, linesOpt=list(lwd=NULL, col=NULL,lty=NULL, type=NULL, pch=NULL), diff --git a/R/pairs.R b/R/pairs.R index d51f46f..20feac9 100644 --- a/R/pairs.R +++ b/R/pairs.R @@ -8,7 +8,9 @@ #' @param ... Passed to \code{cor}. #' #' This function can be used with \code{pairs} to display correlations. -#' @seealso \code{\link[graphics]{pairs}}. +#' @return No return value, called for side effects as a panel function +#' in \code{\link[graphics]{pairs}}. +#' @seealso \code{\link[graphics]{pairs}}. #' @importFrom stats cor #' @export panel.cor <- function(x, y, digits = 2, prefix = "", cex.cor, ...) { @@ -37,11 +39,13 @@ panel.cor <- function(x, y, digits = 2, prefix = "", cex.cor, ...) { #' #' This function can be used with \code{pairs} to display correlations. #' -#' @seealso \code{\link[graphics]{pairs}}. +#' @return No return value, called for side effects as a panel function +#' in \code{\link[graphics]{pairs}}. +#' @seealso \code{\link[graphics]{pairs}}. #' @importFrom stats cor lm #' @importFrom graphics panel.smooth legend abline #' @export -panel.lmSmooth <- function(x,y, col = par("col"), bg = NA, pch = par("pch"), +panel.lmSmooth <- function(x,y, col = par("col"), bg = NA, pch = par("pch"), cex = 0.8, method="spearman", use="complete", ...) { corr <- cor(x,y, method=method, use=use) diff --git a/R/pcaPlots.R b/R/pcaPlots.R index 86afbb3..3e06e56 100644 --- a/R/pcaPlots.R +++ b/R/pcaPlots.R @@ -22,6 +22,7 @@ #' testPCAscores.withReverse <- pcaScores(testPCA, reverse=c(TRUE, FALSE)) #' colMeans(as.matrix(testPCAscores.withReverse)[c(1,3,5),]) #' +#' @return A \code{\link{PCAScoreMatrix}} object containing the PCA scores. #' @export pcaScores pcaScores <- function(x, choices, offset, reverse=c(FALSE, FALSE)) { stopifnot(all(is.logical(reverse)) & length(reverse)<=2) @@ -137,6 +138,7 @@ pcaRotation <- function(x, choices, offset, reverse=c(FALSE, FALSE)) { #' @param x A prcomp object #' @param choices Integer index, choices to plot #' @param ... Other parameters +#' @return Depends on the method; see individual method documentation. #' @export plotPCA plotPCA <- function(x, choices, ...) UseMethod("plotPCA") @@ -407,6 +409,7 @@ plotPCA.prcomp <- function(x, #' @param title Character string #' @param subtitle Character string #' @param ... Passed to \code{\link{plot}} +#' @return No return value, called for side effects (plotting). #' @export plotPCAloading <- function(loadings, x=1L, y=2L, circle=FALSE, title="", subtitle="",...) { plot(loadings[,x],loadings[,y], @@ -427,11 +430,14 @@ plotPCAloading <- function(loadings, x=1L, y=2L, circle=FALSE, title="", subtitl } plotPCAscores <- function(scores, class, legendX, legendY, title="",...) { + oldpar <- par(no.readonly = TRUE) + on.exit(par(oldpar)) + colbase <- brewer.pal.factorLevels(class, name="Set1") cols <- colbase[class] symbol <- rep(c(15:18,1:4),5L) vsym <- symbol[as.numeric(as.factor(class))] - + par(mfrow=c(1,2),oma=c(0,0,2,4)) plot(scores$x[,1],scores$x[,2], pch=vsym, @@ -442,7 +448,7 @@ plotPCAscores <- function(scores, class, legendX, legendY, title="",...) { main="Front View",...) abline(h=0,v=0,lty=2) grid() - + par(mfrow=c(1,2),oma=c(0,4,2,0)) plot(scores$x[,3],scores$x[,2], pch=vsym, @@ -453,8 +459,8 @@ plotPCAscores <- function(scores, class, legendX, legendY, title="",...) { main="Side View",...) abline(h=0,v=0,lty=2) grid() - - par(xpd=NA) # This allows the legend to be printed outside the plot region + + par(xpd=NA) legend(legendX,legendY, levels(class), pch=symbol[levels(class)], @@ -463,7 +469,6 @@ plotPCAscores <- function(scores, class, legendX, legendY, title="",...) { cex=1, pt.cex=2, title="") title(title,outer=TRUE) - par(xpd=F) } @@ -486,6 +491,8 @@ plotPCAscores <- function(scores, class, legendX, legendY, title="",...) { #' lfcMat <- matrix(rnorm(9), nrow=3) #' pcaScoresFromLogFC(lfcMat) #' +#' @return A \code{\link{PCAScoreMatrix}} object containing the PCA scores +#' derived from the log fold-change matrix. #' @export pcaScoresFromLogFC <- function(lfcMat, reference=0, diff --git a/R/utils.R b/R/utils.R index 450754a..30df041 100644 --- a/R/utils.R +++ b/R/utils.R @@ -23,6 +23,8 @@ NULL #' compactPar() #' plot(1:4) #' +#' @return A named list of the previous \code{par} settings (invisibly), +#' as returned by \code{\link{par}}. #' @export compactPar compactPar<- function(mar=c(3,3,1.5,1.5), mgp=c(2,1,0),...) return(par(mar=mar, mgp=mgp, ...)) @@ -35,7 +37,7 @@ compactPar<- function(mar=c(3,3,1.5,1.5), mgp=c(2,1,0),...) return(par(mar=mar, #' @author Jitao David Zhang #' @examples #' -#' \dontrun{ +#' \donttest{ #' op <- par(mfrow=squareLayout(7)) #' plot(1:5) #' plot(2:6) diff --git a/man/brewer.pal.factor.Rd b/man/brewer.pal.factor.Rd index f8fe473..f059d88 100644 --- a/man/brewer.pal.factor.Rd +++ b/man/brewer.pal.factor.Rd @@ -33,10 +33,9 @@ maximum colors. See example below. } \examples{ -\dontrun{ +\donttest{ myFac <- factor(c("HSV", "BVB", "FCB", "HSV", "BVB", "HSV")) brewer.pal.factor(myFac, name="Set1") -brewer.pal.factorLevels(myFac, name="Set1") myLongFac <- factor(paste("Sample", 1:20)) brewer.pal.factor(myLongFac, name="Set1") diff --git a/man/cascadeOrder.Rd b/man/cascadeOrder.Rd index 0248b37..59fe751 100644 --- a/man/cascadeOrder.Rd +++ b/man/cascadeOrder.Rd @@ -12,6 +12,9 @@ cascadeOrder(matrix, dichotomy = c("maxabs", "mean", "median")) \item{dichotomy}{How are the rows divided into two? By maximal abs value (default), mean value, or the median value of each row.} } +\value{ +An integer vector of row indices in cascade order. +} \description{ The 'cascade order' is defined by three criteria (1) Rows are divided into two groups by the condition given by 'dichotomy'. (2) The positive and diff --git a/man/compactPar.Rd b/man/compactPar.Rd index d2fc907..4b4a9a0 100644 --- a/man/compactPar.Rd +++ b/man/compactPar.Rd @@ -13,6 +13,10 @@ compactPar(mar = c(3, 3, 1.5, 1.5), mgp = c(2, 1, 0), ...) \item{...}{other parameters passed to \code{par}} } +\value{ +A named list of the previous \code{par} settings (invisibly), + as returned by \code{\link{par}}. +} \description{ For compact figures } diff --git a/man/expVarLabel.Rd b/man/expVarLabel.Rd index 6a51500..eebab18 100644 --- a/man/expVarLabel.Rd +++ b/man/expVarLabel.Rd @@ -14,6 +14,10 @@ expVarLabel(x, choices, compact) \item{compact}{Logical, whether a compact format is returned, see example} } +\value{ +A character vector of labels describing the explained variance + of each principal component. +} \description{ Generic function expVarLabel to generate a label of explained variance from prcomp and PCAScoreMatrix objects diff --git a/man/getExpVarLabel.Rd b/man/getExpVarLabel.Rd index 3dfb4c1..6aacd9d 100644 --- a/man/getExpVarLabel.Rd +++ b/man/getExpVarLabel.Rd @@ -15,6 +15,10 @@ getExpVarLabel(ev, choices, compact = FALSE) \item{compact}{Logical, either a \code{compact} label is returned, see examples.} } +\value{ +A character vector of labels in the form + \code{"Principal component N (X\% variance explained)"}. +} \description{ Helper function to print PC and explained variances } diff --git a/man/histMat.Rd b/man/histMat.Rd index 19ad6be..fb94f5b 100644 --- a/man/histMat.Rd +++ b/man/histMat.Rd @@ -26,6 +26,10 @@ histMat( \item{\dots}{Other parameters passed to \code{hist}} } +\value{ +Invisibly, a list as returned by \code{\link{hist}}, with + additional elements \code{xlim} and \code{linesOpt}. +} \description{ Make histograms for matrix } diff --git a/man/midCol.Rd b/man/midCol.Rd index cab1f1a..08c64bc 100644 --- a/man/midCol.Rd +++ b/man/midCol.Rd @@ -22,13 +22,13 @@ Blender two colors to get the midpoint color of two colors midCol("black", "red") midCol(c("black", "red")) -\dontrun{ +\donttest{ set.seed(1778) nCol <- 20 candCol <- grep("gr[a|e]y", colors(), value=TRUE, invert=TRUE) firstCols <- sample(candCol, nCol) secondCols <- rev(sample(candCol, nCol)) -midCols <- sapply(seq(along=firstCols), function(i) +midCols <- sapply(seq(along=firstCols), function(i) midCol(firstCols[i], secondCols[i])) plot.new() plot.window(xaxt="n", yaxt="n", xlim=c(0, nCol), @@ -36,7 +36,7 @@ plot.window(xaxt="n", yaxt="n", xlim=c(0, nCol), title("Example of midCol") segments(x0=1:nCol, y0=0, x1=1:nCol, y1=4, col="lightgray") points(x=rep(1:nCol, each=3), - y=rep(1:3, nCol), + y=rep(1:3, nCol), pch=21, cex=1.75, bg=as.vector(rbind(firstCols, midCols, secondCols))) text(0, c(1.5, 2.5, 3.5), c("Second", "Midpoint", "First"), diff --git a/man/panel.cor.Rd b/man/panel.cor.Rd index 767e888..2aecb3b 100644 --- a/man/panel.cor.Rd +++ b/man/panel.cor.Rd @@ -21,6 +21,10 @@ panel.cor(x, y, digits = 2, prefix = "", cex.cor, ...) This function can be used with \code{pairs} to display correlations.} } +\value{ +No return value, called for side effects as a panel function + in \code{\link[graphics]{pairs}}. +} \description{ Correlation panel for pairs } diff --git a/man/panel.lmSmooth.Rd b/man/panel.lmSmooth.Rd index 3c6439f..879857b 100644 --- a/man/panel.lmSmooth.Rd +++ b/man/panel.lmSmooth.Rd @@ -37,6 +37,10 @@ panel.lmSmooth( This function can be used with \code{pairs} to display correlations.} } +\value{ +No return value, called for side effects as a panel function + in \code{\link[graphics]{pairs}}. +} \description{ Correlation panel } diff --git a/man/pcaScores.Rd b/man/pcaScores.Rd index 2737e04..29659f4 100644 --- a/man/pcaScores.Rd +++ b/man/pcaScores.Rd @@ -19,6 +19,9 @@ offset is set to zero.} \item{reverse}{Logical of the same length as \code{choices} or 1 (which will be repeated), indicating whether the sign of values in the indexed axis should be reversed} } +\value{ +A \code{\link{PCAScoreMatrix}} object containing the PCA scores. +} \description{ Retrieve PCA scores from prcomp objects } diff --git a/man/pcaScoresFromLogFC.Rd b/man/pcaScoresFromLogFC.Rd index 5a826da..ba97768 100644 --- a/man/pcaScoresFromLogFC.Rd +++ b/man/pcaScoresFromLogFC.Rd @@ -22,6 +22,10 @@ default: 0} Perform PCA and get scores from a logFC matrix by setting a pseudo profile of no change (0 for all features) at the origin point} } +\value{ +A \code{\link{PCAScoreMatrix}} object containing the PCA scores + derived from the log fold-change matrix. +} \description{ Perform principal component analysis and derive PCA scores from a logFC matrix diff --git a/man/plotPCA.Rd b/man/plotPCA.Rd index 6e13a1c..2eb40ec 100644 --- a/man/plotPCA.Rd +++ b/man/plotPCA.Rd @@ -13,6 +13,9 @@ plotPCA(x, choices, ...) \item{...}{Other parameters} } +\value{ +Depends on the method; see individual method documentation. +} \description{ S3 method plotPCA } diff --git a/man/plotPCAloading.Rd b/man/plotPCAloading.Rd index 3f09ef5..dd77df4 100644 --- a/man/plotPCAloading.Rd +++ b/man/plotPCAloading.Rd @@ -29,6 +29,9 @@ plotPCAloading( \item{...}{Passed to \code{\link{plot}}} } +\value{ +No return value, called for side effects (plotting). +} \description{ Plot PCA loading } diff --git a/man/print.PCAScoreMatrix.Rd b/man/print.PCAScoreMatrix.Rd index fb88d45..1d95362 100644 --- a/man/print.PCAScoreMatrix.Rd +++ b/man/print.PCAScoreMatrix.Rd @@ -12,7 +12,7 @@ \item{...}{Ignored} } \value{ -NULL, side effect is used +The input \code{x}, invisibly. } \description{ Print PCAScoreMatrix diff --git a/man/print.fcol.Rd b/man/print.fcol.Rd index 4203e62..0a3ce3a 100644 --- a/man/print.fcol.Rd +++ b/man/print.fcol.Rd @@ -11,6 +11,9 @@ \item{...}{Not used now} } +\value{ +The input \code{x}, invisibly. +} \description{ Print a fcol object } diff --git a/man/qBreaks.Rd b/man/qBreaks.Rd index db929ce..22c7f9a 100644 --- a/man/qBreaks.Rd +++ b/man/qBreaks.Rd @@ -23,11 +23,8 @@ axis. This is usally larger than the original number of breaks . } \examples{ -\dontrun{ testVal <- rnorm(1000) -qBreaks(testVal, quantiles=c(0.25, 0.75), breaks=100) ## should be about -400 -} +qBreaks(testVal, quantiles=c(0.25, 0.75), breaks=100) } \seealso{ diff --git a/man/setCompactTrellis.Rd b/man/setCompactTrellis.Rd index 77b14f4..b27dc50 100644 --- a/man/setCompactTrellis.Rd +++ b/man/setCompactTrellis.Rd @@ -7,15 +7,18 @@ setCompactTrellis() } \value{ -as \code{lattice.options}. The side-effect is used. +Invisibly, the previous value of the \code{default.theme} + lattice option, so it can be restored manually if needed. } \description{ -The function sets compact trellis options as default +The function sets compact trellis options as default. +The previous \code{lattice.options} are saved and restored +via \code{on.exit} when the calling function exits. } \examples{ -\dontrun{ -setCompactTrellis() +\donttest{ +old <- setCompactTrellis() } } diff --git a/man/squareLayout.Rd b/man/squareLayout.Rd index 4e091fa..8be571c 100644 --- a/man/squareLayout.Rd +++ b/man/squareLayout.Rd @@ -18,7 +18,7 @@ Plan a square/matrix layout of plots } \examples{ - \dontrun{ + \donttest{ op <- par(mfrow=squareLayout(7)) plot(1:5) plot(2:6)