is_xxx_for_decimal_point: What does the current locale specify for the decimal point?

Description Usage Arguments Value References See Also Examples

View source: R/is-decimal-point.R

Description

Does the current locale specify a comma or a period for the decimal point?

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
assert_is_comma_for_decimal_point(
  severity = getOption("assertive.severity", "stop")
)

assert_is_period_for_decimal_point(
  severity = getOption("assertive.severity", "stop")
)

is_xxx_for_decimal_point(dp, type = c("numbers", "money"))

is_comma_for_decimal_point(type = c("numbers", "money"))

is_period_for_decimal_point(type = c("numbers", "money"))

Arguments

severity

How severe should the consequences of the assertion be? Either "stop", "warning", "message", or "none".

dp

Character to be used as a decimal point.

type

Decimal point for numbers or money?

Value

is_comma_for_decimal_point returns TRUE when the current locale uses a comma for a decimal place, as determined by Sys.localeconv. Similarly, is_period_for_decimal_point returns TRUE when the current locale uses a period (a.k.a. full stop) for a decimal place. If R has been compiled without support for locales, then the value will always be NA.

References

http://www.cplusplus.com/reference/clocale/lconv/

See Also

Sys.localeconv

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# Current settings:
is_comma_for_decimal_point()
is_comma_for_decimal_point("money")
# Or equivalently:
is_period_for_decimal_point()
is_period_for_decimal_point("money")
# A useful guess for reading in files:
read_csv <- if(is_comma_for_decimal_point()) read.csv else read.csv2 
## Not run: 
# Force locale and test (may require admin rights)
current_locale <- sys_get_locale()
a_period_locale <- if(is_windows()) 
{
  "English_United Kingdom.1252"
} else if(is_mac()) 
{
  "en_GB"
} else if(is_linux()) 
{
  "en_GB.utf8"
} else 
{
  "en"
}
sys_set_locale(LC_ALL = a_period_locale)
assert_is_period_for_decimal_point()
a_comma_locale <- if(is_windows())
{
  "French_France.1252"
} else if(is_mac()) 
{
  "fr_FR"
} else if(is_linux()) 
{
  "fr_FR.utf8" 
} else 
{
  "fr"
}
sys_set_locale(LC_ALL = a_comma_locale)
assert_is_comma_for_decimal_point()
suppressWarnings(sys_set_locale(l = current_locale))

## End(Not run)

assertive.reflection documentation built on July 31, 2020, 1:06 a.m.