Set or get locale-specific information

DESCRIPTION:

Set or get aspects of the locale for the Splus process.

USAGE:

Sys.setlocale(category="LC_ALL", locale="")
Sys.getlocale(category="LC_ALL")
Sys.withlocale(expr, category = "LC_ALL", locale)
Sys.localeconv()

ARGUMENTS:

category
character string. Must be one of "LC_ALL", "LC_COLLATE", "LC_CTYPE", "LC_MONETARY", LC_NUMERIC", or "LC_TIME". "LC_ALL" means the collection of all the others.
locale
character string. A valid locale name. The default, "", means the default locale for your system as determined by the Windows Regional Settings or by Unix environmental variables and "C" means the locale used by the C language (7 bit ASCII characters and US style numbers). Other valid values are system specific. The output of Sys.getlocale() should be a valid input for Sys.setlocale().
expr
An S-Plus expression to evaluate in the given locale.

VALUE:

Sys.setlocale() will return a string describing the current locale after setting it to what you asked for. If the locale string is not valid it will return "" without an error message. Sys.getlocale() will return a string describing the current locale. That string is suitable for input as the locale argument to Sys.setlocale(). Sys.withlocale() will evaluate an expression in a given locale. Sys.localeconv() will return a character vector with names describing various aspects of how to format numbers and money in that locale. E.g., the "decimal_point" element tells whether the decimal point symbol is a period or comma and the "int_curr_symbol" gives the international currency abbreviation for the local currency.

SIDE EFFECTS:

The locale determines which characters are considered printable or alphabetic, the format of numerals, and the collating sequence of characters. Most Splus output and input functions will respect the locale setting. The parser does not and considers a fixed set of Latin1 characters to be alphabetic. Hence deparse does the same. data.dump and data.restore do not follow the current locale either in an effort to make these produce files that may be read on any system.

DETAILS:

Changing "LC_CTYPE" affects which set of characters are displayed as octal codes. E.g., in the "C" locale the character "\341" is printed as "\341" but in Western European based locales it is printed as "a acute". Changing "LC_COLLATE" affects the sort order of character strings. E.g., in the "C" all the lowercase letters are sorted after all the uppercase letters and accented letters come after all unaccented letters but in other locales all letters based on "a" come first.

Changing "LC_NUMERIC" changes the decimal mark used when displaying or reading numbers with functions like print, cat, write.table , scan, and read.table . This also affects functions like as.numeric and as.character when converting between strings and numbers. In the "C" and in most English influenced locales the decimal mark is a period and in many European influenced locales the decimal mark is a comma. "LC_NUMERIC" also affects the thousands separator symbol, but this is rarely used. Note that the expression parser, hence deparse(), always uses the period for a decimal mark to avoid ambiguities in expressions like c(3,1416) . This will make default plot axis labels (xlab and ylab) use decimal periods, although the plot tick labels will follow the locale.

Changing "LC_MONETARY" or "LC_TIME" has no effect on S-PLUS at this time. See class.timeDate for information on how to change the way S-PLUS interprets date and time information. Look at your system's help on Windows Regional Settings or the C functions setlocale() and localeconv() for more details.

Sys.localeconv() would be more convenient if it returned a list instead of a character vector, but we do this for historical reasons.

By default importData and exportData do not use the current numeric locale settings, but the argument use.locale=T will cause them to do so.

SEE ALSO:

EXAMPLES:

## Use default locale from operating system
## This is a useful thing to put in SHOME/local/S.init
Sys.setlocale(locale="")
## Use S-PLUS's default locale
Sys.setlocale(locale="C")
## turn off locale-specific sorting
Sys.setlocale(cat = "LC_COLLATE", locale = "C")
## convert to 1 and 2/10 regardless of current locale
Sys.withlocale(as.numeric("1.2"), locale = "C")
## The following will have the y axis label "log(x+0.1)"
## in any locale (the tick labels will follow the locale).
x<-0:2
plot(x, log(x+0.1))
## To get a comma for the decimal point in y axis label do
plot(x, log(x+0.1), ylab="log(x+0,1)")