創建源對象。
參數
- file
 - 
文件路徑、連接或文字數據(單個字符串或原始向量)。
以
.gz、.bz2、.xz或.zip結尾的文件將自動解壓縮。將自動下載以http://、https://、ftp://或ftps://開頭的文件。遠程gz文件也可以自動下載並解壓。文字數據對於示例和測試最有用。要被識別為文字數據,輸入必須用
I()包裝,是包含至少一個換行符的字符串,或者是至少包含一個帶有換行符的字符串的向量。使用值
clipboard()將從係統剪貼板讀取。 - skip
 - 
讀取數據之前要跳過的行數。
 
例子
# Literal csv
datasource("a,b,c\n1,2,3")
#> [[1]]
#> [1] "a,b,c\n1,2,3"
#> 
#> $skip
#> [1] 0
#> 
#> $skip_empty_rows
#> [1] FALSE
#> 
#> $comment
#> [1] ""
#> 
#> $skip_quote
#> [1] TRUE
#> 
#> attr(,"class")
#> [1] "source_string" "source"       
datasource(charToRaw("a,b,c\n1,2,3"))
#> [[1]]
#>  [1] 61 2c 62 2c 63 0a 31 2c 32 2c 33
#> 
#> $skip
#> [1] 0
#> 
#> $skip_empty_rows
#> [1] FALSE
#> 
#> $comment
#> [1] ""
#> 
#> $skip_quote
#> [1] TRUE
#> 
#> attr(,"class")
#> [1] "source_raw" "source"    
# Strings
datasource(readr_example("mtcars.csv"))
#> [[1]]
#> [1] "/home/runner/work/_temp/Library/readr/extdata/mtcars.csv"
#> 
#> $skip
#> [1] 0
#> 
#> $skip_empty_rows
#> [1] FALSE
#> 
#> $comment
#> [1] ""
#> 
#> $skip_quote
#> [1] TRUE
#> 
#> attr(,"class")
#> [1] "source_file" "source"     
datasource(readr_example("mtcars.csv.bz2"))
#> [[1]]
#> [1] "/tmp/RtmpwhXCeJ/file16954d2fa625"
#> 
#> $skip
#> [1] 0
#> 
#> $skip_empty_rows
#> [1] FALSE
#> 
#> $comment
#> [1] ""
#> 
#> $skip_quote
#> [1] TRUE
#> 
#> $env
#> <environment: 0x560265776300>
#> 
#> attr(,"class")
#> [1] "source_file" "source"     
datasource(readr_example("mtcars.csv.zip"))
#> [[1]]
#> [1] "/tmp/RtmpwhXCeJ/file169548b95bc1"
#> 
#> $skip
#> [1] 0
#> 
#> $skip_empty_rows
#> [1] FALSE
#> 
#> $comment
#> [1] ""
#> 
#> $skip_quote
#> [1] TRUE
#> 
#> $env
#> <environment: 0x560265432610>
#> 
#> attr(,"class")
#> [1] "source_file" "source"     
if (FALSE) {
datasource("https://github.com/tidyverse/readr/raw/main/inst/extdata/mtcars.csv")
}
# Connection
con <- rawConnection(charToRaw("abc\n123"))
datasource(con)
#> [[1]]
#> [1] "/tmp/RtmpwhXCeJ/file16951ef34a16"
#> 
#> $skip
#> [1] 0
#> 
#> $skip_empty_rows
#> [1] FALSE
#> 
#> $comment
#> [1] ""
#> 
#> $skip_quote
#> [1] TRUE
#> 
#> $env
#> <environment: 0x560264d40dc8>
#> 
#> attr(,"class")
#> [1] "source_file" "source"     
close(con)
相關用法
- R readr date_names 創建或檢索日期名稱
 - 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 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 count_fields 計算文件每一行中的字段數
 - R readr read_table 將空格分隔的列讀入 tibble
 - R readr problems 檢索解析問題
 - R readr parse_guess 使用“最佳”類型進行解析
 - R readr parse_datetime 解析日期/時間
 - R readr read_file 讀/寫完整文件
 
注:本文由純淨天空篩選整理自Hadley Wickham等大神的英文原創作品 Create a source object.。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
