diff --git a/NAMESPACE b/NAMESPACE index 5039851..06f361c 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,4 +1,5 @@ # Generated by roxygen2: do not edit by hand +export("*") export("+") export(C) diff --git a/R/C.R b/R/C.R index c4a792e..6b800af 100644 --- a/R/C.R +++ b/R/C.R @@ -12,5 +12,5 @@ C <- function(...){ Load() x <- as.numeric(paste0(...)) - ifelse(length(x), x, 0) + if(length(x))x else 0 } diff --git a/R/stringRepetition.R b/R/stringRepetition.R new file mode 100644 index 0000000..e5db949 --- /dev/null +++ b/R/stringRepetition.R @@ -0,0 +1,22 @@ +#' Character repetition +#' +#' Shorthand for \code{paste(rep(e1, each = e2), collapse = "")}. Works like regular multiplication if \code{e1} is not character. +#' +#' @param e1 +#' @param e2 +#' +#' @return Character if \code{e1} is character, regular output otherwise. +#' @export +#' +#' @examples +#' 2*2 +#' "A"*2 +#' "A"*2+1 +#' "A"*(2+1) +`*` <- function(e1, e2){ + if(is.character(e1)){ + paste(rep(e1, each = e2), collapse = "") + } else { + .Primitive("*")(e1, e2) + } +} diff --git a/man/times.Rd b/man/times.Rd new file mode 100644 index 0000000..c8cbcca --- /dev/null +++ b/man/times.Rd @@ -0,0 +1,25 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/stringRepetition.R +\name{*} +\alias{*} +\title{Character repetition} +\usage{ +"*"(e1, e2) +} +\arguments{ +\item{e1}{} + +\item{e2}{} +} +\value{ +Character if \code{e1} is character, regular output otherwise. +} +\description{ +Shorthand for \code{paste(rep(e1, each = e2), collapse = "")}. Works like regular multiplication if \code{e1} is not character. +} +\examples{ +2*2 +"A"*2 +"A"*2+1 +"A"*(2+1) +}