當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。