cols() 包括輸入數據中的所有列,猜測列類型為默認值。 cols_only() 僅包含您明確指定的列,跳過其餘列。一般來說,您可以用 list() 替換 cols(),而不改變行為。
參數
- ...
 - 
由
col_*()創建的列對象或其縮寫字符名稱(如read_delim()的col_types參數中所述)。如果您隻覆蓋幾列,最好按名稱引用列。如果未命名,列類型必須與列名稱完全匹配。 - .default
 - 
...中未顯式覆蓋的任何命名列都將使用此列類型讀取。 
細節
可用的規格有:(括號內為字符串縮寫)
- 
col_logical()[l],僅包含T、F、TRUE或FALSE。 - 
col_integer()[i],整數。 - 
col_double()[d],雙打。 - 
col_character()[c],其他一切。 - 
col_factor(levels, ordered)[f],一組固定值。 - 
col_date(format = "")[D]:使用語言環境的date_format。 - 
col_time(format = "")[t]:使用語言環境的time_format。 - 
col_datetime(format = "")[T]:ISO8601 日期時間 - 
col_number()[n],包含grouping_mark的數字 - 
col_skip()[_, -],不要導入此列。 - 
col_guess()[?],根據輸入使用"best"類型進行解析。 
也可以看看
其他解析器:col_skip() ,  cols_condense() ,  parse_datetime() ,  parse_factor() ,  parse_guess() ,  parse_logical() ,  parse_number() ,  parse_vector()
例子
cols(a = col_integer())
#> cols(
#>   a = col_integer()
#> )
cols_only(a = col_integer())
#> cols_only(
#>   a = col_integer()
#> )
# You can also use the standard abbreviations
cols(a = "i")
#> cols(
#>   a = col_integer()
#> )
cols(a = "i", b = "d", c = "_")
#> cols(
#>   a = col_integer(),
#>   b = col_double(),
#>   c = col_skip()
#> )
# You can also use multiple sets of column definitions by combining
# them like so:
t1 <- cols(
  column_one = col_integer(),
  column_two = col_number()
)
t2 <- cols(
  column_three = col_character()
)
t3 <- t1
t3$cols <- c(t1$cols, t2$cols)
t3
#> cols(
#>   column_one = col_integer(),
#>   column_two = col_number(),
#>   column_three = col_character()
#> )
相關用法
- R readr count_fields 計算文件每一行中的字段數
 - 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 write_delim 將數據幀寫入分隔文件
 - R readr parse_vector 解析字符向量。
 - R readr with_edition 暫時更改活動閱讀器版本
 - 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 read_table 將空格分隔的列讀入 tibble
 - R readr problems 檢索解析問題
 - R readr parse_guess 使用“最佳”類型進行解析
 - R readr parse_datetime 解析日期/時間
 
注:本文由純淨天空篩選整理自Hadley Wickham等大神的英文原創作品 Create column specification。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
