with_edition()
允許您更改給定代碼塊的 readr 的活動版本。 local_edition()
允許您更改 readr 的活動版本,直到當前函數或文件結束。
例子
with_edition(1, edition_get())
#> [1] 1
with_edition(2, edition_get())
#> [1] 2
# readr 1e and 2e behave differently when input rows have different number
# number of fields
with_edition(1, read_csv("1,2\n3,4,5", col_names = c("X", "Y", "Z")))
#> Warning: 1 parsing failure.
#> row col expected actual file
#> 1 -- 3 columns 2 columns literal data
#> # A tibble: 2 × 3
#> X Y Z
#> <dbl> <dbl> <dbl>
#> 1 1 2 NA
#> 2 3 4 5
with_edition(2, read_csv("1,2\n3,4,5", col_names = c("X", "Y", "Z")))
#> Warning: One or more parsing issues, call `problems()` on your data frame for
#> details, e.g.:
#> dat <- vroom(...)
#> problems(dat)
#> Rows: 2 Columns: 2
#> ── Column specification ──────────────────────────────────────────────────
#> Delimiter: ","
#> dbl (1): X
#> num (1): Y
#>
#> ℹ Use `spec()` to retrieve the full column specification for this data.
#> ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
#> # A tibble: 2 × 2
#> X Y
#> <dbl> <dbl>
#> 1 1 2
#> 2 3 45
# local_edition() applies in a specific scope, for example, inside a function
read_csv_1e <- function(...) {
local_edition(1)
read_csv(...)
}
read_csv("1,2\n3,4,5", col_names = c("X", "Y", "Z")) # 2e behaviour
#> Warning: One or more parsing issues, call `problems()` on your data frame for
#> details, e.g.:
#> dat <- vroom(...)
#> problems(dat)
#> Rows: 2 Columns: 2
#> ── Column specification ──────────────────────────────────────────────────
#> Delimiter: ","
#> dbl (1): X
#> num (1): Y
#>
#> ℹ Use `spec()` to retrieve the full column specification for this data.
#> ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
#> # A tibble: 2 × 2
#> X Y
#> <dbl> <dbl>
#> 1 1 2
#> 2 3 45
read_csv_1e("1,2\n3,4,5", col_names = c("X", "Y", "Z")) # 1e behaviour
#> Warning: 1 parsing failure.
#> row col expected actual file
#> 1 -- 3 columns 2 columns literal data
#> # A tibble: 2 × 3
#> X Y Z
#> <dbl> <dbl> <dbl>
#> 1 1 2 NA
#> 2 3 4 5
read_csv("1,2\n3,4,5", col_names = c("X", "Y", "Z")) # 2e behaviour
#> Warning: One or more parsing issues, call `problems()` on your data frame for
#> details, e.g.:
#> dat <- vroom(...)
#> problems(dat)
#> Rows: 2 Columns: 2
#> ── Column specification ──────────────────────────────────────────────────
#> Delimiter: ","
#> dbl (1): X
#> num (1): Y
#>
#> ℹ Use `spec()` to retrieve the full column specification for this data.
#> ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
#> # A tibble: 2 × 2
#> X Y
#> <dbl> <dbl>
#> 1 1 2
#> 2 3 45
相關用法
- R readr write_delim 將數據幀寫入分隔文件
- R readr datasource 創建源對象。
- R readr melt_delim 返回分隔文件中每個標記的熔化數據(包括 csv 和 tsv)
- R readr read_rds 讀/寫 RDS 文件。
- R readr read_lines 從文件中讀取/寫入行
- R readr parse_number 靈活地解析數字
- R readr read_fwf 將固定寬度文件讀入 tibble
- R readr read_builtin 從包中讀取內置對象
- R readr Tokenizers 分詞器。
- R readr melt_table 返回空格分隔文件中每個標記的熔化數據
- R readr date_names 創建或檢索日期名稱
- R readr type_convert 重新轉換現有 DataFrame 中的字符列
- R readr locale 創建語言環境
- R readr parse_vector 解析字符向量。
- R readr read_delim 將分隔文件(包括 CSV 和 TSV)讀入 tibble
- R readr format_delim 將 DataFrame 轉換為分隔字符串
- R readr edition_get 檢索當前活動版本
- R readr readr_example 獲取 readr 示例的路徑
- R readr melt_fwf 返回固定寬度文件中每個標記的熔化數據
- R readr count_fields 計算文件每一行中的字段數
- R readr read_table 將空格分隔的列讀入 tibble
- R readr problems 檢索解析問題
- R readr parse_guess 使用“最佳”類型進行解析
- R readr parse_datetime 解析日期/時間
- R readr read_file 讀/寫完整文件
注:本文由純淨天空篩選整理自Hadley Wickham等大神的英文原創作品 Temporarily change the active readr edition。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。