创建源对象。
参数
- 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.。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。
