This function is meant to avoid issues that arise when sorting a vector of
numbers that have been converted to character
. For example,
import_scn
automatically reads in the first column (with
FreeSurfer outputs this is the column of subject IDs) as a
character
variable. If the subject IDs had been all numbers/integers,
then sorting (i.e., setting the key
in a data.table
) would be
incorrect: e.g., it might be '1', '10', '2', ...
.
If “x” is a numeric vector, then the resultant string width will be
determined by max(x)
or x
itself if the input is a single
integer. For example, if x=10
, it will return '01', '02', ...,
'10'
. If “x” is a character vector, then the output's string width
will be max(nchar(x))
. For example, if x
includes both
'1'
and '1000'
, it will return '0001'
, etc.