mirror of
https://github.com/agdamsbo/stRoke.git
synced 2024-11-24 13:41:55 +01:00
padding
This commit is contained in:
parent
0cde2918ee
commit
8133684f54
@ -4,13 +4,15 @@
|
|||||||
#' @param length final string length
|
#' @param length final string length
|
||||||
#' @param after if padding should be added after as opposed to default before
|
#' @param after if padding should be added after as opposed to default before
|
||||||
#' @param pad padding string of length 1
|
#' @param pad padding string of length 1
|
||||||
|
#' @param lead leading string for all. Number or character vector. Cycled.
|
||||||
|
#' @param tail tailing string for all. Number or character vector. Cycled.
|
||||||
#'
|
#'
|
||||||
#' @return vector or character strings of same length.
|
#' @return vector or character strings of same length.
|
||||||
#' @export
|
#' @export
|
||||||
#'
|
#'
|
||||||
#' @examples
|
#' @examples
|
||||||
#' add_padding(sample(1:200,5))
|
#' add_padding(sample(1:200,5),tail="AA",lead=c(2,3,"e"))
|
||||||
add_padding <- function(d,length=NULL,after=FALSE,pad="0"){
|
add_padding <- function(d,length=NULL,after=FALSE,pad="0",lead=NULL,tail=NULL){
|
||||||
if (!is.vector(d)) {
|
if (!is.vector(d)) {
|
||||||
stop("Please supply vector")
|
stop("Please supply vector")
|
||||||
}
|
}
|
||||||
@ -31,8 +33,11 @@ add_padding <- function(d,length=NULL,after=FALSE,pad="0"){
|
|||||||
paste(rep(pad,i),collapse="")}))
|
paste(rep(pad,i),collapse="")}))
|
||||||
|
|
||||||
if (after) {
|
if (after) {
|
||||||
paste0(d,ps)
|
out <- paste0(d,ps)
|
||||||
} else {
|
} else {
|
||||||
paste0(ps,d)
|
out <- paste0(ps,d)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
paste0(lead,out,tail)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,14 @@
|
|||||||
\alias{add_padding}
|
\alias{add_padding}
|
||||||
\title{Add padding to string}
|
\title{Add padding to string}
|
||||||
\usage{
|
\usage{
|
||||||
add_padding(d, length = NULL, after = FALSE, pad = "0")
|
add_padding(
|
||||||
|
d,
|
||||||
|
length = NULL,
|
||||||
|
after = FALSE,
|
||||||
|
pad = "0",
|
||||||
|
lead = NULL,
|
||||||
|
tail = NULL
|
||||||
|
)
|
||||||
}
|
}
|
||||||
\arguments{
|
\arguments{
|
||||||
\item{d}{vector of strings or numbers}
|
\item{d}{vector of strings or numbers}
|
||||||
@ -14,6 +21,10 @@ add_padding(d, length = NULL, after = FALSE, pad = "0")
|
|||||||
\item{after}{if padding should be added after as opposed to default before}
|
\item{after}{if padding should be added after as opposed to default before}
|
||||||
|
|
||||||
\item{pad}{padding string of length 1}
|
\item{pad}{padding string of length 1}
|
||||||
|
|
||||||
|
\item{lead}{leading string for all. Number or character vector. Cycled.}
|
||||||
|
|
||||||
|
\item{tail}{tailing string for all. Number or character vector. Cycled.}
|
||||||
}
|
}
|
||||||
\value{
|
\value{
|
||||||
vector or character strings of same length.
|
vector or character strings of same length.
|
||||||
@ -22,5 +33,5 @@ vector or character strings of same length.
|
|||||||
Add padding to string
|
Add padding to string
|
||||||
}
|
}
|
||||||
\examples{
|
\examples{
|
||||||
add_padding(sample(1:200,5))
|
add_padding(sample(1:200,5),tail="AA",lead=c(2,3,"e"))
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user