xy_formatC: A wrapper for 'formatC'

Description Usage Arguments Value

Description

This wrapper for formatC includes code that allows for some additional tweaking to be taken care of when a number is converted to a text-string. It was primarily created in order to resolve an issue related to the disappearance of trailing zeros when adding numbers to a ggplot. (Reminder: The problem occurred when parse=TRUE was used when adding text/labels.)

Usage

1
2
xy_formatC(x, digits = 3, not_IEC60559 = TRUE, .plotmath = TRUE,
  .decimal = ".")

Arguments

x

The number that should be converted to text.

digits

A number, default value 3, to be given to the digits-argument of round.

.plotmath

A logical value, default TRUE, which will ensure that the format of the returned character-string works as desired when included as a part of some text or label in a ggplot. In particular, this ensures that any trailing zeros are properly preserved when parse=TRUE is used when adding the text.

.decimal

A character, default value ., which is to be used for the decimal sign for the converted number. This enables the decimal sign to be replaced with ,, which is of interest for those countries where that is the norm.

not_IEC60599

A logical value, default TRUE, which can be used to round x in the same manner a human normally would do, e.g. that "2.5" rounds to "3" instead of "2". Reminder: This is included to avoid that students must be explained why the rounding used in the text is different from what they themselves have computed.

Value

A character-string based on x, modified according to the description given in the arguments digits, not_IEC60599, .plotmath and .decimal. Reminder: The result will have an attribute named equal, which is included sine the intended use of this function is that it will be called from xy_sprintf, which then will either add an equality sign or an approximation sign based on the value of the equal-attribute.


LAJordanger/HVLstatistikk documentation built on June 21, 2019, 7:56 p.m.