FileFormat
包含關於如何讀取和解析 Dataset
中檔案的資訊。有對應於支援檔案格式的子類別 (ParquetFileFormat
和 IpcFileFormat
)。
工廠方法
FileFormat$create()
接受以下引數
format
:檔案格式的字串識別符。目前支援的值"parquet"
"ipc"/"arrow"/"feather",彼此之間都是別名;對於 Feather,請注意僅支援版本 2 的檔案
"csv"/"text",相同事物的別名 (因為逗號是文字檔案的預設分隔符號)
"tsv",等同於傳遞
format = "text", delimiter = "\t"
...
:其他格式特定的選項format = "parquet"
:dict_columns
:應讀取為字典的欄位名稱。來自 FragmentScanOptions 的任何 Parquet 選項。
format = "text"
:請參閱 CsvParseOptions。請注意,您可以使用 Arrow C++ 程式庫命名 ("delimiter"、"quoting" 等) 或readr
風格的命名 (用於read_csv_arrow()
) ("delim"、"quote" 等) 來指定它們。並非所有readr
選項目前都受到支援;如果您遇到arrow
應該支援的選項,請提交 issue。此外,還支援以下選項。來自 CsvReadOptionsskip_rows
column_names
。請注意,如果指定了 Schema,則column_names
必須與 schema 中指定的名稱相符。autogenerate_column_names
來自 CsvFragmentScanOptions (這些值可以在掃描時覆寫)convert_options
:CsvConvertOptionsblock_size
它會傳回 FileFormat
的適當子類別 (例如 ParquetFileFormat
)
範例
## Semi-colon delimited files
# Set up directory for examples
tf <- tempfile()
dir.create(tf)
on.exit(unlink(tf))
write.table(mtcars, file.path(tf, "file1.txt"), sep = ";", row.names = FALSE)
# Create FileFormat object
format <- FileFormat$create(format = "text", delimiter = ";")
open_dataset(tf, format = format)
#> FileSystemDataset with 1 csv file
#> 11 columns
#> mpg: double
#> cyl: int64
#> disp: double
#> hp: int64
#> drat: double
#> wt: double
#> qsec: double
#> vs: int64
#> am: int64
#> gear: int64
#> carb: int64