当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


R reprex reprex_locale 在特定区域设置中渲染 reprex


渲染 reprex() ,控制错误消息的本地化和区域设置的各个方面。请注意,这些是相关但不同的问题!典型用法是让西班牙语系统上的某人创建一个更容易让 English-speaking 受众遵循的代表。

用法

reprex_locale(..., language = "en", locale = NULL)

参数

...

输入传递到 reprex()

language

指定消息的首选语言的字符串。它是在 reprex() 调用期间通过 LANGUAGE 环境变量制定的。示例:"en" 表示英语,"fr" 表示法语。查看详情了解更多。

locale

命名字符向量,在 Sys.setlocale() 意义上指定区域设置的各个方面。它是通过在 reprex() 调用期间设置一个或多个环境变量来制定的。查看详情了解更多。

渲染的 reprex 的字符向量,不可见。

language

使用language 参数来表达错误消息的首选语言。 dir(system.file(package = "translations")) 的输出可能会提供一些有用的想法。 language 通常应遵循 "XPG syntax":两个字母的语言代码,可选地后跟其他修饰符。

示例:"en""de""en_GB""pt_BR"

locale

仅当您想要影响诸如day-of-the-week 或月份如何转换为字符之类的内容时,才使用locale 参数。与 language 参数相比,您不太可能需要设置此参数。设置特定类别(例如 "LC_TIME" )可能比设置 multi-category 快捷方式(例如 "LC_ALL""LANG" )更成功。 locale 值必须遵循操作系统规定的格式,并且必须安装请求的区域设置。在 *nix 系统上,locale -a 是查看安装了哪些语言环境的好方法。请注意,localelanguage 在 Windows 上的格式彼此不同。

示例:"en_CA.UTF-8" (macOS)、"French_France.1252" (Windows)。

也可以看看

例子

if (FALSE) {

# if all you want to do is make sure messages are in English
reprex_locale("a" / 2)

# change messages to a specific language
reprex_locale(
  {
    "a" / 2
  },
  language = "it"
)

reprex_locale(
  {
    "a" / 2
  },
  language = "fr_CA"
)

reprex_locale(
  {
    "a" / 2
  },
  language = "pt_BR"
)

# get day-of-week and month to print in French (not Windows)
reprex_locale(
  {
    format(as.Date(c("2019-01-01", "2019-02-01")), "%a %b %d")
  },
  locale = c(LC_TIME = "fr_FR")
)

# get day-of-week and month to print in French (Windows)
# assumes that the relevant language is installed on the system
# LC_TIME can also be specified as "French" or "French_France" here
reprex_locale(
  {
    format(as.Date(c("2019-01-01", "2019-02-01")), "%a %b %d")
  },
  locale = c(LC_TIME = "French_France.1252")
)
}
源代码:R/reprex-locale.R

相关用法


注:本文由纯净天空筛选整理自Jennifer Bryan等大神的英文原创作品 Render a reprex in a specific locale。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。