Added the new function int2padstr().

Using a combination of format() and gsub().
The purpose is to simplify looping through many datafiles
in a single report using for-loops.
A way was needed to "convert" the for-loop's counting variable
into a string of set length padded with zeroes.
This function fills that need.
master
Taha Ahmed 14 years ago
parent c810ef66ba
commit 2c48474584

@ -3,6 +3,7 @@
# Taha Ahmed, Jan 2011 # Taha Ahmed, Jan 2011
# CONTENTS # CONTENTS
# >>>> int2padstr
# >>>> It2charge # >>>> It2charge
# >>>> ProvideSampleId # >>>> ProvideSampleId
# >>>> ConvertRefPot # >>>> ConvertRefPot
@ -14,6 +15,29 @@
##################################################
################## int2padstr ####################
##################################################
int2padstr <- function (ii, pchr, w) {
## Description:
## Converts an integer or a vector of integers to
## a string padded with characters.
## Usage:
## int2padstr(ii, pchr, w)
## Arguments:
## ii: integer or vector of integers
## pchr: a padding character (e.g., "0")
## w: width of the return string (an integer)
## Make sure to set the width longer than
## or equal to the length of the biggest integer.
## For example, if the integers (ii) are
## in the range 1 - 100, set w to at least 3.
## Value:
## A character string or a vector of character strings
gsub(" ", pchr, formatC(ii, format="s", mode="character", width = w))
}
################################################## ##################################################
################### It2charge #################### ################### It2charge ####################
################################################## ##################################################

Loading…
Cancel
Save