From 9f1dc14e1861019ceb5f16353d1f36589c22667d Mon Sep 17 00:00:00 2001 From: Sam217pa Date: Sat, 2 May 2020 18:22:07 +0200 Subject: [PATCH 1/2] pass ellipsis to scale_x_continuous --- R/utils.R | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/R/utils.R b/R/utils.R index 560d527..3960ed2 100644 --- a/R/utils.R +++ b/R/utils.R @@ -441,15 +441,17 @@ trans_seq_rev<- function(unit = c("Mb", "kb", "bp")){ function(x) {paste(x, unit)} } -scale_x_sequnit <- function(unit = c("Mb", "kb", "bp"), append = NULL){ +scale_x_sequnit <- function(unit = c("Mb", "kb", "bp"), append = NULL, ...){ unit <- match.arg(unit) if(is.null(append)){ scale_x_continuous(breaks = trans_breaks(trans_seq(unit), trans_seq_rev(unit)), - labels = trans_format(trans_seq_format(unit), math_format(.x))) - }else{ + labels = trans_format(trans_seq_format(unit), math_format(.x)), + ...) + } else { stopifnot(is.character(append)) - scale_x_continuous(labels = trans_format(.append_unit(append), math_format(.x))) + scale_x_continuous(labels = trans_format(.append_unit(append), math_format(.x)), + ...) } } From a8d7c19b964200844b1eb986162a0e99b22fa080 Mon Sep 17 00:00:00 2001 From: sam217pa Date: Tue, 5 May 2020 10:24:39 +0200 Subject: [PATCH 2/2] check arguments passed and update man page fix typo in man page (disalbe -> disable) --- R/utils.R | 26 +++++++++++++++++++------- man/scale_x_sequnit.Rd | 17 +++++++++++------ 2 files changed, 30 insertions(+), 13 deletions(-) diff --git a/R/utils.R b/R/utils.R index 3960ed2..43ae0bd 100644 --- a/R/utils.R +++ b/R/utils.R @@ -443,15 +443,27 @@ trans_seq_rev<- function(unit = c("Mb", "kb", "bp")){ scale_x_sequnit <- function(unit = c("Mb", "kb", "bp"), append = NULL, ...){ unit <- match.arg(unit) + check_args <- function() { + kwargs <- names(list(...)) + if (is.null(append)) { + if (any(c("breaks", "labels") %in% kwargs)) + stop("scale_x_sequnit already sets breaks and labels arguments when 'append' is set.") + } else { + stopifnot(is.character(append)) + if ("labels" %in% names(list(...))) + stop("scale_x_sequnit already sets 'labels' argument.") + } + } + check_args() if(is.null(append)){ - scale_x_continuous(breaks = trans_breaks(trans_seq(unit), - trans_seq_rev(unit)), - labels = trans_format(trans_seq_format(unit), math_format(.x)), - ...) + scale_x_continuous( + breaks = trans_breaks(trans_seq(unit), trans_seq_rev(unit)), + labels = trans_format(trans_seq_format(unit), math_format(.x)), + ...) } else { - stopifnot(is.character(append)) - scale_x_continuous(labels = trans_format(.append_unit(append), math_format(.x)), - ...) + scale_x_continuous( + labels = trans_format(.append_unit(append), math_format(.x)), + ...) } } diff --git a/man/scale_x_sequnit.Rd b/man/scale_x_sequnit.Rd index 813c69f..878674e 100644 --- a/man/scale_x_sequnit.Rd +++ b/man/scale_x_sequnit.Rd @@ -5,17 +5,22 @@ scale x by unit 'Mb','kb', 'bp'. } \usage{ -scale_x_sequnit(unit = c("Mb", "kb", "bp"), append = NULL) +scale_x_sequnit(unit = c("Mb", "kb", "bp"), append = NULL, ...) } \arguments{ \item{unit}{ - unit to scale x. Default is Mb. + unit to scale x. Default is Mb. } \item{append}{ - default \code{NULL}. If pass a character, it disalbe unit and arbitrarily append a - text behind the original x scale numbers. + default \code{NULL}. If pass a character, it disable unit and arbitrarily append a + text behind the original x scale numbers. + } + \item{...}{ + arguments to pass to \code{scale_x_continuous}. + Note that \code{scale_x_sequnit} sets breaks and labels + automatically, so arguments \code{breaks} and \code{labels} cannot + be passed (\code{breaks} can if \code{append} is not set). } - } \value{ 'position_c' @@ -30,4 +35,4 @@ p + scale_x_sequnit("kb") p + scale_x_sequnit("bp") } \author{Tengfei Yin} - +\author{samuel barreto}