------------恢復內容開始------------
看到sprintf函數有點不明所以,原文如下
為了用指定的格式數值型轉換成字符型, 可以使用sprintf()函數, 其用法與C語言的sprintf()函數相似, 只不過是向量化的。例如
sprintf('file%03d.txt', c(1, 99, 100))
## [1] "file001.txt" "file099.txt" "file100.txt"
sprintf()
Use C-style String Formatting Commands
Description
A wrapper for the C function sprintf, that returns a character vector containing a formatted combination of text and variable values.
Usage
sprintf(fmt, ...)
gettextf(fmt, ..., domain = NULL)
Arguments
fmt 格式化字符串
a character vector of format strings, each of up to 8192 bytes.
...
values to be passed into fmt. Only logical, integer, real and character vectors are supported, but some coercion will be done: see the ‘Details’ section. Up to 100.
domain
see gettext.
Details
sprintf is a wrapper for the system sprintf C-library function. Attempts are made to check that the mode of the values passed match the format supplied, and R's special values (NA, Inf, -Inf and NaN) are handled correctly.
gettextf is a convenience function which provides C-style string formatting with possible translation of the format string.
The arguments (including fmt) are recycled if possible a whole number of times to the length of the longest, and then the formatting is done in parallel. Zero-length arguments are allowed and will give a zero-length result. All arguments are evaluated even if unused, and hence some types (e.g., "symbol" or "language", see typeof) are not allowed.
The following is abstracted from Kernighan and Ritchie (see References): however the actual implementation will follow the C99 standard and fine details (especially the behaviour under user error) may depend on the platform.
------------恢復內容結束------------