Converts numeric values to character strings for reporting.
printnum(x, ...)# S3 method for default
printnum(x, na_string = getOption("papaja.na_string"), ...)
# S3 method for list
printnum(x, ...)
# S3 method for integer
printnum(
x,
numerals = TRUE,
capitalize = FALSE,
zero_string = "no",
na_string = getOption("papaja.na_string"),
...
)
# S3 method for numeric
printnum(
x,
gt1 = TRUE,
zero = TRUE,
margin = 1,
na_string = getOption("papaja.na_string"),
use_math = TRUE,
add_equals = FALSE,
...
)
# S3 method for data.frame
printnum(x, margin = 2, ...)
# S3 method for matrix
printnum(x, margin = 2, ...)
# S3 method for papaja_labelled
printnum(x, ...)
Numeric. Can be either a single value, vector, or matrix.
Arguments passed on to base::formatC
digits
the desired number of digits after the decimal
point (format = "f"
) or significant digits
(format = "g"
, = "e"
or = "fg"
).
Default: 2 for integer, 4 for real numbers. If less than 0,
the C default of 6 digits is used. If specified as more than 50, 50
will be used with a warning unless format = "f"
where it is
limited to typically 324. (Not more than 15--21 digits need be
accurate, depending on the OS and compiler used. This limit is
just a precaution against segfaults in the underlying C runtime.)
width
the total field width; if both digits
and
width
are unspecified, width
defaults to 1,
otherwise to digits + 1
. width = 0
will use
width = digits
, width < 0
means left
justify the number in this field (equivalent to flag = "-"
).
If necessary, the result will have more characters than
width
. For character data this is interpreted in characters
(not bytes nor display width).
format
equal to "d"
(for integers), "f"
,
"e"
, "E"
, "g"
, "G"
, "fg"
(for
reals), or "s"
(for strings). Default is "d"
for
integers, "g"
for reals.
"f"
gives numbers in the usual
xxx.xxx
format; "e"
and "E"
give n.ddde+nn
or
n.dddE+nn
(scientific format); "g"
and "G"
put
x[i]
into scientific format only if it saves space to do so
and drop trailing zeros and decimal point - unless flag
contains "#"
which keeps trailing zeros for the "g", "G"
formats.
"fg"
(our own hybrid format) uses fixed format as "f"
,
but digits
as the minimum number of significant digits.
This can lead to quite long result strings, see examples below. Note
that unlike signif
this prints large numbers with
more significant digits than digits
. Trailing zeros are
dropped in this format, unless flag
contains
"#"
.
flag
for formatC
, a character string giving a
format modifier as in Kernighan and Ritchie (1988, page 243) or the
C+99 standard.
"0"
pads leading zeros;
"-"
does left adjustment,
"+"
ensures a sign in all cases, i.e., "+"
for
positive numbers ,
" "
if the first character is not a sign, the space
character " "
will be used instead.
"#"
specifies “an alternative output form”,
specifically depending on format
.
"'"
on some platform--locale combination, activates “thousands' grouping” for decimal conversion,
"I"
in some versions of glibc
allow for integer
conversion to use the locale's alternative output digits, if any.
character
formatting, but signal
an error since R 3.4.0.mode
"double"
(or "real"
), "integer"
or
"character"
.
Default: Determined from the storage mode of x
.
big.mark
character; if not empty used as mark between every
big.interval
decimals before (hence big
) the
decimal point.
big.interval
see big.mark
above; defaults to 3.
small.mark
character; if not empty used as mark between every
small.interval
decimals after (hence small
) the
decimal point.
small.interval
see small.mark
above; defaults to 5.
decimal.mark
the character to be used to indicate the numeric decimal point.
preserve.width
string specifying if the string widths should
be preserved where possible in those cases where marks
(big.mark
or small.mark
) are added. "common"
,
the default, corresponds to format
-like behavior
whereas "individual"
is the default in
formatC()
. Value can be abbreviated.
zero.print
logical, character string or NULL
specifying
if and how zeros should be formatted specially. Useful for
pretty printing ‘sparse’ objects.
replace.zero
logical; if zero.print
is a
character string, indicates if the exact zero entries in x
should be simply replaced by zero.print
. Otherwise,
depending on the widths of the respective strings, the (formatted)
zeroes are partly replaced by zero.print
and then
padded with " "
to the right were applicable. In that case
(false replace[.zero]
), if the zero.print
string does
not fit, a warning is produced (if warn.non.fitting
is true).
This works via prettyNum()
, which calls .format.zeros(*,
replace=replace.zero)
three times in this case, see the ‘Details’.
drop0trailing
logical, indicating if trailing zeros,
i.e., "0"
after the decimal mark, should be removed;
also drops "e+00"
in exponential formats. This is simply passed
to prettyNum()
, see the ‘Details’.
Character. String to print if element of x
is NA
.
Logical. Indicates if integer should be returned as words.
Logical. Indicates if first letter should be capitalized. Ignored if numberals = TURE
.
Character. Word to print if x
is a zero integer.
Logical. Indicates if the absolute value of the statistic can, in principal, greater than 1.
Logical. Indicates if the statistic can, in principal, be 0.
Integer. If x
is a matrix, the function is applied either across rows (margin = 1
)
or columns (margin = 2
).
Logical. Indicates whether to insert $
into the output so that Inf
or scientific
notation is rendered correctly.
Logical. Indicates if the output string should be prepended with an equals sign.
If x
is a vector, digits
, gt1
, and zero
can be vectors
according to which each element of the vector is formated. Parameters are recycled if length of x
exceeds length of the parameter vectors. If x
is a matrix, the vectors specify the formating
of either rows or columns according to the value of margin
.
# NOT RUN {
printnum(1/3)
printnum(1/3, gt1 = FALSE)
printnum(1/3, digits = 5)
printnum(0)
printnum(0, zero = FALSE)
printp(0.0001)
# }
Run the code above in your browser using DataLab