Skip to content
Snippets Groups Projects
Commit 6b4a53b1 authored by Laura A DeCicco's avatar Laura A DeCicco
Browse files

Added a short function, padVariable to help with problems of losing leading 0's.

parent 86d40a57
No related branches found
No related tags found
No related merge requests found
#' Pad string with leading zeros
#'
#' Function to pad a string with leading zeros. Useful for parameter codes and USGS site IDs.
#'
#' @param x string
#' @param padTo number Final desired length of the string
#' @keywords data import USGS web service
#' @return x string returned with leading zeros
#' @export
#' @examples
#' pCode <- '10'
#' correctPCode <- padVariable(pCode,5)
padVariable <- function(x,padTo){
numDigits <- nchar(x)
if (padTo != numDigits){
leadingZeros <- paste(rep("0",(padTo-numDigits)),collapse="",sep="")
x <- paste(leadingZeros,x,sep="")
}
return(x)
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment