渲染 reprex()
,控製錯誤消息的本地化和區域設置的各個方麵。請注意,這些是相關但不同的問題!典型用法是讓西班牙語係統上的某人創建一個更容易讓 English-speaking 受眾遵循的代表。
參數
- ...
-
輸入傳遞到
reprex()
。 - language
-
指定消息的首選語言的字符串。它是在
reprex()
調用期間通過LANGUAGE
環境變量製定的。示例:"en"
表示英語,"fr"
表示法語。查看詳情了解更多。 - locale
-
命名字符向量,在
Sys.setlocale()
意義上指定區域設置的各個方麵。它是通過在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
是查看安裝了哪些語言環境的好方法。請注意,locale
和 language
在 Windows 上的格式彼此不同。
示例:"en_CA.UTF-8"
(macOS)、"French_France.1252"
(Windows)。
也可以看看
-
GNU C 文檔的 Locale Names 部分,了解有關 XPG 語法的更多信息
-
R 安裝和管理手冊的 Internationalization and Localization 部分
例子
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 reprex_render 在新的 R 會話中渲染文檔
- R reprex reprex_document 代表輸出格式
- R reprex reprex 渲染一個reprex
- R reprex un-reprex 取消渲染reprex
- R SparkR repartition用法及代碼示例
- R SparkR repartitionByRange用法及代碼示例
- R SparkR read.stream用法及代碼示例
- R readr datasource 創建源對象。
- R readr melt_delim 返回分隔文件中每個標記的熔化數據(包括 csv 和 tsv)
- R readr read_rds 讀/寫 RDS 文件。
- R readr read_lines 從文件中讀取/寫入行
- R readr parse_number 靈活地解析數字
- R SparkR refreshByPath用法及代碼示例
- R readr read_fwf 將固定寬度文件讀入 tibble
- R readxl read_excel 讀取 xls 和 xlsx 文件
- R SparkR refreshTable用法及代碼示例
- R readr read_builtin 從包中讀取內置對象
- R readr Tokenizers 分詞器。
- R readr melt_table 返回空格分隔文件中每個標記的熔化數據
- R readr date_names 創建或檢索日期名稱
- R SparkR read.jdbc用法及代碼示例
- R readr type_convert 重新轉換現有 DataFrame 中的字符列
- R readxl excel_sheets 列出 Excel 電子表格中的所有工作表
- R readxl readxl_example 獲取 readxl 示例的路徑
- R readxl excel_format 確定文件格式
注:本文由純淨天空篩選整理自Jennifer Bryan等大神的英文原創作品 Render a reprex in a specific locale。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。