nameleadzero: Add leading zeros to character for easy sequential naming of...

Description Usage Arguments Details Value Author(s) Examples

View source: R/nameleadzero.R

Description

Returns a character with leading zeros according to the total number of filenames to be created. Useful when exporting multiple images arising from imported video data stored as a matrix or dataframe. By providing a base root name, the function will then add leading zeroes ahead of the number suffix (counter variable), according to the no.digits requested (i.e. Img0001.png, Img0002.png,...Img9999.png). Best used inside a loop exporting images.

Usage

1
nameleadzero(filenameroot = "Img", filetype = ".png", no.digits = 5, counter = 1)

Arguments

filenameroot

Prefix or root filename, supplied as a character vector.

filetype

The type of file to be saved, as a character. i.e. ".png", or ".csv".

no.digits

The total number of digits required for the suffix portion of the complete filename. Use 2 if numbers range from 1 to 99.

counter

The specific counter to add to the suffix. Typically counter is a number.

Details

Although this returns a single character value with leading zeros, it could be used in a loop to create a new, incremented file name (i.e. Img0001.png, Img0002.png, Img0003.png,... Img9999.png), or wrapped in an apply function:

Value

Returns a character value.

Author(s)

Glenn J Tattersall

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
# Using for-loop 
prefix<-"Img_"
filetype<-".png"
no.digits<-2
for(i in 1:10){
  f.txt<-nameleadzero(prefix, filetype, no.digits, counter=i)
  print(f.txt)
}

# Using an apply function
x<-unlist(lapply(1:10, nameleadzero, filenameroot="Img_", filetype=".png", no.digits=2))
x

Thermimage documentation built on Sept. 27, 2021, 5:11 p.m.