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


R readr read_delim 將分隔文件(包括 CSV 和 TSV)讀入 tibble


read_csv()read_tsv() 是更通用的 read_delim() 的特殊情況。它們對於讀取最常見類型的平麵文件數據、逗號分隔值和製表符分隔值非常有用。 read_csv2() 使用 ; 作為字段分隔符,使用 , 作為小數點。這種格式在一些歐洲國家很常見。

用法

read_delim(
  file,
  delim = NULL,
  quote = "\"",
  escape_backslash = FALSE,
  escape_double = TRUE,
  col_names = TRUE,
  col_types = NULL,
  col_select = NULL,
  id = NULL,
  locale = default_locale(),
  na = c("", "NA"),
  quoted_na = TRUE,
  comment = "",
  trim_ws = FALSE,
  skip = 0,
  n_max = Inf,
  guess_max = min(1000, n_max),
  name_repair = "unique",
  num_threads = readr_threads(),
  progress = show_progress(),
  show_col_types = should_show_types(),
  skip_empty_rows = TRUE,
  lazy = should_read_lazy()
)

read_csv(
  file,
  col_names = TRUE,
  col_types = NULL,
  col_select = NULL,
  id = NULL,
  locale = default_locale(),
  na = c("", "NA"),
  quoted_na = TRUE,
  quote = "\"",
  comment = "",
  trim_ws = TRUE,
  skip = 0,
  n_max = Inf,
  guess_max = min(1000, n_max),
  name_repair = "unique",
  num_threads = readr_threads(),
  progress = show_progress(),
  show_col_types = should_show_types(),
  skip_empty_rows = TRUE,
  lazy = should_read_lazy()
)

read_csv2(
  file,
  col_names = TRUE,
  col_types = NULL,
  col_select = NULL,
  id = NULL,
  locale = default_locale(),
  na = c("", "NA"),
  quoted_na = TRUE,
  quote = "\"",
  comment = "",
  trim_ws = TRUE,
  skip = 0,
  n_max = Inf,
  guess_max = min(1000, n_max),
  progress = show_progress(),
  name_repair = "unique",
  num_threads = readr_threads(),
  show_col_types = should_show_types(),
  skip_empty_rows = TRUE,
  lazy = should_read_lazy()
)

read_tsv(
  file,
  col_names = TRUE,
  col_types = NULL,
  col_select = NULL,
  id = NULL,
  locale = default_locale(),
  na = c("", "NA"),
  quoted_na = TRUE,
  quote = "\"",
  comment = "",
  trim_ws = TRUE,
  skip = 0,
  n_max = Inf,
  guess_max = min(1000, n_max),
  progress = show_progress(),
  name_repair = "unique",
  num_threads = readr_threads(),
  show_col_types = should_show_types(),
  skip_empty_rows = TRUE,
  lazy = should_read_lazy()
)

參數

file

文件路徑、連接或文字數據(單個字符串或原始向量)。

.gz.bz2.xz.zip 結尾的文件將自動解壓縮。將自動下載以 http://https://ftp://ftps:// 開頭的文件。遠程gz文件也可以自動下載並解壓。

文字數據對於示例和測試最有用。要被識別為文字數據,輸入必須用 I() 包裝,是包含至少一個換行符的字符串,或者是至少包含一個帶有換行符的字符串的向量。

使用值 clipboard() 將從係統剪貼板讀取。

delim

用於分隔記錄中的字段的單個字符。

quote

用於引用字符串的單個字符。

escape_backslash

文件是否使用反斜杠來轉義特殊字符?這比 escape_double 更通用,因為反斜杠可用於轉義分隔符、引號字符,或添加特殊字符,例如 \\n

escape_double

文件是否通過加倍引號來轉義引號?即,如果此選項為 TRUE ,則值 """" 表示單引號 \"

col_names

TRUEFALSE 或列名稱的字符向量。

如果 TRUE ,輸入的第一行將用作列名稱,並且不會包含在 DataFrame 中。如果 FALSE ,將自動生成列名稱:X1、X2、X3 等。

如果 col_names 是字符向量,則這些值將用作列的名稱,並且輸入的第一行將被讀入輸出數據幀的第一行。

缺少 ( NA ) 列名將生成警告,並用虛擬名稱 ...1...2 等進行填充。重複的列名將生成警告並使其唯一,請參閱 name_repair 來控製其方式完畢。

col_types

NULLcols() 規範或字符串之一。有關更多詳細信息,請參閱vignette("readr")

如果是 NULL ,則所有列類型都將從輸入的 guess_max 行推斷出來,散布在整個文件中。這很方便(而且快速),但不夠穩健。如果猜測的類型錯誤,您需要增加 guess_max 或自己提供正確的類型。

list()cols() 創建的列規範必須為每一列包含一個列規範。如果您隻想讀取列的子集,請使用 cols_only()

或者,您可以使用緊湊的字符串表示形式,其中每個字符代表一列:

  • c = 字符

  • 我 = 整數

  • n = 數字

  • d = 雙

  • l = 邏輯

  • f = 因子

  • D = 日期

  • T = 日期時間

  • t = 時間

  • ? = 猜猜

  • _ 或 - = 跳過

默認情況下,讀取沒有列規範的文件將打印一條消息,顯示 readr 猜測的內容。要刪除此消息,請設置 show_col_types = FALSE 或設置 `options(readr.show_col_types = FALSE)。

col_select

要包含在結果中的列。您可以使用與dplyr::select() 相同的mini-language 來按名稱引用列。使用c() 可以使用多個選擇表達式。盡管這種用法不太常見,col_select 也接受數字列索引。有關選擇語言的完整詳細信息,請參閱?tidyselect::language

id

用於存儲文件路徑的列的名稱。當讀取多個輸入文件並且文件路徑中有數據(例如數據收集日期)時,這非常有用。如果NULL(默認值)則不會創建額外的列。

locale

區域設置控製默認值因地而異。默認區域設置為 US-centric(如 R),但您可以使用 locale() 創建自己的區域設置來控製默認時區、編碼、小數標記、大標記和日/月名稱等內容。

na

要解釋為缺失值的字符串的字符向量。將此選項設置為 character() 以指示沒有缺失值。

quoted_na

引號內的缺失值是否應被視為缺失值(默認)或字符串。從 readr 2.0.0 開始,此參數已被軟棄用。

comment

用於標識評論的字符串。注釋字符之後的任何文本都將被默默忽略。

trim_ws

在解析每個字段之前是否應該刪除前導和尾隨空格(ASCII 空格和製表符)?

skip

讀取數據之前要跳過的行數。如果提供comment,則跳過後任何注釋行都將被忽略。

n_max

讀取的最大行數。

guess_max

用於猜測列類型的最大行數。永遠不會使用超過讀取的行數。有關更多詳細信息,請參閱vignette("column-types", package = "readr")

name_repair

列名的處理。默認行為是確保列名稱為 "unique" 。支持多種修複策略:

  • "minimal":除了名稱的基本存在之外,沒有名稱修複或檢查。

  • "unique"(默認值):確保名稱唯一且不為空。

  • "check_unique" :沒有名稱修複,但檢查它們是 unique

  • "universal" :將名稱命名為 unique 並進行語法設置。

  • 函數:應用自定義名稱修複(例如,name_repair = make.names 用於基本 R 樣式的名稱)。

  • purrr-style 匿名函數,請參閱rlang::as_function()

此參數作為 repair 傳遞到 vctrs::vec_as_names() 。有關這些條款以及用於執行這些條款的策略的更多詳細信息,請參閱此處。

num_threads

用於初始解析和延遲讀取數據的處理線程數。如果您的數據在字段中包含換行符,解析器應自動檢測到這一點並回退到僅使用一個線程。但是,如果您知道文件在帶引號的字段中包含換行符,那麽顯式設置 num_threads = 1 是最安全的。

progress

顯示進度條?默認情況下,它隻會在交互式會話中顯示,而不會在編織文檔時顯示。可以通過將選項 readr.show_progress 設置為 FALSE 來禁用自動進度條。

show_col_types

如果是 FALSE ,則不顯示猜測的列類型。如果 TRUE 始終顯示列類型,即使提供了列類型。如果 NULL(默認)僅在 col_types 參數未顯式提供列類型時顯示列類型。

skip_empty_rows

空白行應該被完全忽略嗎?即,如果此選項是TRUE,則根本不會表示空白行。如果是FALSE,則它們將由所有列中的NA 值表示。

lazy

懶惰地讀取值?默認情況下,這是 FALSE ,因為延遲讀取文件時有一些特殊的考慮因子,這導致了一些用戶的錯誤。具體來說,讀取然後寫回同一個文件時,事情會變得很棘手。但是,一般來說,惰性讀取 ( lazy = TRUE ) 有很多好處,特別是對於交互式使用以及當您的下遊工作僅涉及行或列的子集時。

should_read_lazy()vroom::vroom()altrep 參數的文檔中了解更多信息。

一個tibble()。如果存在解析問題,則會出現警告提醒您。您可以通過在數據集上調用 problems() 來檢索完整的詳細信息。

例子

# Input sources -------------------------------------------------------------
# Read from a path
read_csv(readr_example("mtcars.csv"))
#> Rows: 32 Columns: 11
#> ── Column specification ──────────────────────────────────────────────────
#> Delimiter: ","
#> dbl (11): mpg, cyl, disp, hp, drat, wt, qsec, vs, am, gear, carb
#> 
#> ℹ 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: 32 × 11
#>      mpg   cyl  disp    hp  drat    wt  qsec    vs    am  gear  carb
#>    <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
#>  1  21       6  160    110  3.9   2.62  16.5     0     1     4     4
#>  2  21       6  160    110  3.9   2.88  17.0     0     1     4     4
#>  3  22.8     4  108     93  3.85  2.32  18.6     1     1     4     1
#>  4  21.4     6  258    110  3.08  3.22  19.4     1     0     3     1
#>  5  18.7     8  360    175  3.15  3.44  17.0     0     0     3     2
#>  6  18.1     6  225    105  2.76  3.46  20.2     1     0     3     1
#>  7  14.3     8  360    245  3.21  3.57  15.8     0     0     3     4
#>  8  24.4     4  147.    62  3.69  3.19  20       1     0     4     2
#>  9  22.8     4  141.    95  3.92  3.15  22.9     1     0     4     2
#> 10  19.2     6  168.   123  3.92  3.44  18.3     1     0     4     4
#> # … with 22 more rows
read_csv(readr_example("mtcars.csv.zip"))
#> Rows: 32 Columns: 11
#> ── Column specification ──────────────────────────────────────────────────
#> Delimiter: ","
#> dbl (11): mpg, cyl, disp, hp, drat, wt, qsec, vs, am, gear, carb
#> 
#> ℹ 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: 32 × 11
#>      mpg   cyl  disp    hp  drat    wt  qsec    vs    am  gear  carb
#>    <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
#>  1  21       6  160    110  3.9   2.62  16.5     0     1     4     4
#>  2  21       6  160    110  3.9   2.88  17.0     0     1     4     4
#>  3  22.8     4  108     93  3.85  2.32  18.6     1     1     4     1
#>  4  21.4     6  258    110  3.08  3.22  19.4     1     0     3     1
#>  5  18.7     8  360    175  3.15  3.44  17.0     0     0     3     2
#>  6  18.1     6  225    105  2.76  3.46  20.2     1     0     3     1
#>  7  14.3     8  360    245  3.21  3.57  15.8     0     0     3     4
#>  8  24.4     4  147.    62  3.69  3.19  20       1     0     4     2
#>  9  22.8     4  141.    95  3.92  3.15  22.9     1     0     4     2
#> 10  19.2     6  168.   123  3.92  3.44  18.3     1     0     4     4
#> # … with 22 more rows
read_csv(readr_example("mtcars.csv.bz2"))
#> Rows: 32 Columns: 11
#> ── Column specification ──────────────────────────────────────────────────
#> Delimiter: ","
#> dbl (11): mpg, cyl, disp, hp, drat, wt, qsec, vs, am, gear, carb
#> 
#> ℹ 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: 32 × 11
#>      mpg   cyl  disp    hp  drat    wt  qsec    vs    am  gear  carb
#>    <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
#>  1  21       6  160    110  3.9   2.62  16.5     0     1     4     4
#>  2  21       6  160    110  3.9   2.88  17.0     0     1     4     4
#>  3  22.8     4  108     93  3.85  2.32  18.6     1     1     4     1
#>  4  21.4     6  258    110  3.08  3.22  19.4     1     0     3     1
#>  5  18.7     8  360    175  3.15  3.44  17.0     0     0     3     2
#>  6  18.1     6  225    105  2.76  3.46  20.2     1     0     3     1
#>  7  14.3     8  360    245  3.21  3.57  15.8     0     0     3     4
#>  8  24.4     4  147.    62  3.69  3.19  20       1     0     4     2
#>  9  22.8     4  141.    95  3.92  3.15  22.9     1     0     4     2
#> 10  19.2     6  168.   123  3.92  3.44  18.3     1     0     4     4
#> # … with 22 more rows
if (FALSE) {
# Including remote paths
read_csv("https://github.com/tidyverse/readr/raw/main/inst/extdata/mtcars.csv")
}

# Read from multiple file paths at once
continents <- c("africa", "americas", "asia", "europe", "oceania")
filepaths <- vapply(
  paste0("mini-gapminder-", continents, ".csv"),
  FUN = readr_example,
  FUN.VALUE = character(1)
)
read_csv(filepaths, id = "file")
#> Rows: 26 Columns: 6
#> ── Column specification ──────────────────────────────────────────────────
#> Delimiter: ","
#> chr (1): country
#> dbl (4): year, lifeExp, pop, gdpPercap
#> 
#> ℹ 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: 26 × 6
#>    file                               country  year lifeExp    pop gdpPe…¹
#>    <chr>                              <chr>   <dbl>   <dbl>  <dbl>   <dbl>
#>  1 /home/runner/work/_temp/Library/r… Algeria  1952    43.1 9.28e6   2449.
#>  2 /home/runner/work/_temp/Library/r… Angola   1952    30.0 4.23e6   3521.
#>  3 /home/runner/work/_temp/Library/r… Benin    1952    38.2 1.74e6   1063.
#>  4 /home/runner/work/_temp/Library/r… Botswa…  1952    47.6 4.42e5    851.
#>  5 /home/runner/work/_temp/Library/r… Burkin…  1952    32.0 4.47e6    543.
#>  6 /home/runner/work/_temp/Library/r… Burundi  1952    39.0 2.45e6    339.
#>  7 /home/runner/work/_temp/Library/r… Argent…  1952    62.5 1.79e7   5911.
#>  8 /home/runner/work/_temp/Library/r… Bolivia  1952    40.4 2.88e6   2677.
#>  9 /home/runner/work/_temp/Library/r… Brazil   1952    50.9 5.66e7   2109.
#> 10 /home/runner/work/_temp/Library/r… Canada   1952    68.8 1.48e7  11367.
#> # … with 16 more rows, and abbreviated variable name ¹gdpPercap

# Or directly from a string with `I()`
read_csv(I("x,y\n1,2\n3,4"))
#> Rows: 2 Columns: 2
#> ── Column specification ──────────────────────────────────────────────────
#> Delimiter: ","
#> dbl (2): x, 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     4

# Column selection-----------------------------------------------------------
# Pass column names or indexes directly to select them
read_csv(readr_example("chickens.csv"), col_select = c(chicken, eggs_laid))
#> Rows: 5 Columns: 2
#> ── Column specification ──────────────────────────────────────────────────
#> Delimiter: ","
#> chr (1): chicken
#> dbl (1): eggs_laid
#> 
#> ℹ 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: 5 × 2
#>   chicken                 eggs_laid
#>   <chr>                       <dbl>
#> 1 Foghorn Leghorn                 0
#> 2 Chicken Little                  3
#> 3 Ginger                         12
#> 4 Camilla the Chicken             7
#> 5 Ernie The Giant Chicken         0
read_csv(readr_example("chickens.csv"), col_select = c(1, 3:4))
#> Rows: 5 Columns: 3
#> ── Column specification ──────────────────────────────────────────────────
#> Delimiter: ","
#> chr (2): chicken, motto
#> dbl (1): eggs_laid
#> 
#> ℹ 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: 5 × 3
#>   chicken                 eggs_laid motto                                 
#>   <chr>                       <dbl> <chr>                                 
#> 1 Foghorn Leghorn                 0 That's a joke, ah say, that's a joke,…
#> 2 Chicken Little                  3 The sky is falling!                   
#> 3 Ginger                         12 Listen. We'll either die free chicken…
#> 4 Camilla the Chicken             7 Bawk, buck, ba-gawk.                  
#> 5 Ernie The Giant Chicken         0 Put Captain Solo in the cargo hold.   

# Or use the selection helpers
read_csv(
  readr_example("chickens.csv"),
  col_select = c(starts_with("c"), last_col())
)
#> Rows: 5 Columns: 2
#> ── Column specification ──────────────────────────────────────────────────
#> Delimiter: ","
#> chr (2): chicken, motto
#> 
#> ℹ 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: 5 × 2
#>   chicken                 motto                                           
#>   <chr>                   <chr>                                           
#> 1 Foghorn Leghorn         That's a joke, ah say, that's a joke, son.      
#> 2 Chicken Little          The sky is falling!                             
#> 3 Ginger                  Listen. We'll either die free chickens or we di…
#> 4 Camilla the Chicken     Bawk, buck, ba-gawk.                            
#> 5 Ernie The Giant Chicken Put Captain Solo in the cargo hold.             

# You can also rename specific columns
read_csv(
  readr_example("chickens.csv"),
  col_select = c(egg_yield = eggs_laid, everything())
)
#> Rows: 5 Columns: 4
#> ── Column specification ──────────────────────────────────────────────────
#> Delimiter: ","
#> chr (3): chicken, sex, motto
#> dbl (1): eggs_laid
#> 
#> ℹ 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: 5 × 4
#>   egg_yield chicken                 sex     motto                         
#>       <dbl> <chr>                   <chr>   <chr>                         
#> 1         0 Foghorn Leghorn         rooster That's a joke, ah say, that's…
#> 2         3 Chicken Little          hen     The sky is falling!           
#> 3        12 Ginger                  hen     Listen. We'll either die free…
#> 4         7 Camilla the Chicken     hen     Bawk, buck, ba-gawk.          
#> 5         0 Ernie The Giant Chicken rooster Put Captain Solo in the cargo…

# Column types --------------------------------------------------------------
# By default, readr guesses the columns types, looking at `guess_max` rows.
# You can override with a compact specification:
read_csv(I("x,y\n1,2\n3,4"), col_types = "dc")
#> # A tibble: 2 × 2
#>       x y    
#>   <dbl> <chr>
#> 1     1 2    
#> 2     3 4    

# Or with a list of column types:
read_csv(I("x,y\n1,2\n3,4"), col_types = list(col_double(), col_character()))
#> # A tibble: 2 × 2
#>       x y    
#>   <dbl> <chr>
#> 1     1 2    
#> 2     3 4    

# If there are parsing problems, you get a warning, and can extract
# more details with problems()
y <- read_csv(I("x\n1\n2\nb"), col_types = list(col_double()))
#> Warning: One or more parsing issues, call `problems()` on your data frame for
#> details, e.g.:
#>   dat <- vroom(...)
#>   problems(dat)
y
#> # A tibble: 3 × 1
#>       x
#>   <dbl>
#> 1     1
#> 2     2
#> 3    NA
problems(y)
#> # A tibble: 1 × 5
#>     row   col expected actual file                            
#>   <int> <int> <chr>    <chr>  <chr>                           
#> 1     4     1 a double b      /tmp/RtmpwhXCeJ/file16952e55c60b

# Column names --------------------------------------------------------------
# By default, readr duplicate name repair is noisy
read_csv(I("x,x\n1,2\n3,4"))
#> New names:
#> • `x` -> `x...1`
#> • `x` -> `x...2`
#> Rows: 2 Columns: 2
#> ── Column specification ──────────────────────────────────────────────────
#> Delimiter: ","
#> dbl (2): x...1, x...2
#> 
#> ℹ 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...1 x...2
#>   <dbl> <dbl>
#> 1     1     2
#> 2     3     4

# To quiet, set the option that controls verbosity of name repair
withr::with_options(
  list(rlib_name_repair_verbosity = "quiet"),
  read_csv(I("x,x\n1,2\n3,4"))
)
#> Rows: 2 Columns: 2
#> ── Column specification ──────────────────────────────────────────────────
#> Delimiter: ","
#> dbl (2): x...1, x...2
#> 
#> ℹ 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...1 x...2
#>   <dbl> <dbl>
#> 1     1     2
#> 2     3     4

# Or use "minimal" to turn off name repair
read_csv(I("x,x\n1,2\n3,4"), name_repair = "minimal")
#> Rows: 2 Columns: 2
#> ── Column specification ──────────────────────────────────────────────────
#> Delimiter: ","
#> dbl (2): x, x
#> 
#> ℹ 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     x
#>   <dbl> <dbl>
#> 1     1     2
#> 2     3     4

# File types ----------------------------------------------------------------
read_csv(I("a,b\n1.0,2.0"))
#> Rows: 1 Columns: 2
#> ── Column specification ──────────────────────────────────────────────────
#> Delimiter: ","
#> dbl (2): a, b
#> 
#> ℹ 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: 1 × 2
#>       a     b
#>   <dbl> <dbl>
#> 1     1     2
read_csv2(I("a;b\n1,0;2,0"))
#> ℹ Using "','" as decimal and "'.'" as grouping mark. Use `read_delim()` for more control.
#> Rows: 1 Columns: 2
#> ── Column specification ──────────────────────────────────────────────────
#> Delimiter: ";"
#> dbl (2): a, b
#> 
#> ℹ 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: 1 × 2
#>       a     b
#>   <dbl> <dbl>
#> 1     1     2
read_tsv(I("a\tb\n1.0\t2.0"))
#> Rows: 1 Columns: 2
#> ── Column specification ──────────────────────────────────────────────────
#> Delimiter: "\t"
#> dbl (2): a, b
#> 
#> ℹ 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: 1 × 2
#>       a     b
#>   <dbl> <dbl>
#> 1     1     2
read_delim(I("a|b\n1.0|2.0"), delim = "|")
#> Rows: 1 Columns: 2
#> ── Column specification ──────────────────────────────────────────────────
#> Delimiter: "|"
#> dbl (2): a, b
#> 
#> ℹ 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: 1 × 2
#>       a     b
#>   <dbl> <dbl>
#> 1     1     2
源代碼:R/read_delim.R

相關用法


注:本文由純淨天空篩選整理自Hadley Wickham等大神的英文原創作品 Read a delimited file (including CSV and TSV) into a tibble。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。