AddLeadingZeros: Add leading zeros to numbers while preserving other text

View source: R/AddLeadingZeros.R

AddLeadingZerosR Documentation

Add leading zeros to numbers while preserving other text

Description

This function is created to fix problems caused by a serious bug in Excel. Editing csv files in that program causes leading zeros to disappear.

Usage

AddLeadingZeros(
  codes,
  places,
  warningText = NULL,
  viaFactor = TRUE,
  nWarning = 6,
  removeLeadingTrailingWhitespace = TRUE
)

Arguments

codes

Character vector

places

Number of places for positive numbers. Minus sign is extra

warningText

When non-NULL, warning will be produced

viaFactor

When TRUE, the algorithm uses factor coding internally.

nWarning

Number of elements to be written before ... in warnings.

removeLeadingTrailingWhitespace

Remove leading and trailing whitespace

Value

Character vector

Author(s)

Øyvind Langsrud

Examples

AddLeadingZeros(c("1", "ABC", "12345", " 23", "-8", "45 ", " -9", " Agent ", "007", 
                  "7 James Bond "), 10)
AddLeadingZeros(c("1", "ABC", "12345", " 23", "-8", "45 ", " -9", " Agent ", "007", 
                  "7 James Bond "), 4)
AddLeadingZeros(c("1", "ABC", "12345", " 23", "-8", "45 ", " -9", " Agent ", "007", 
                  "7 James Bond "), 4, removeLeadingTrailingWhitespace = FALSE)
AddLeadingZeros(c("1", "ABC", "12345", " 23", "-8", "45 ", " -9", " Agent ", "007", 
                  "7 James Bond "), 4, warningText = "string changes")
AddLeadingZeros(c("1", "ABC", "12345", " 23", "-8", "45 ", " -9", " Agent ", "007", 
                  "7 James Bond "), 4, warningText = "", nWarning = 2)

SSBtools documentation built on Oct. 30, 2024, 5:09 p.m.