CSVFileFormat 是 FileFormat 的子类,它包含有关如何读取和解析 CSV Dataset 中文件的信息。
工厂
CSVFileFormat$create() 可以接受以列表形式传递的选项,作为 parse_options、read_options 或 convert_options 参数。另外,也可以单独传递 readr 风格的选项。虽然可以传入 CSVReadOptions、CSVConvertOptions 和 CSVParseOptions 对象,但不建议这样做,因为这些对象中设置的选项未经过兼容性验证。
示例
# Set up directory for examples
tf <- tempfile()
dir.create(tf)
on.exit(unlink(tf))
df <- data.frame(x = c("1", "2", "NULL"))
write.table(df, file.path(tf, "file1.txt"), sep = ",", row.names = FALSE)
# Create CsvFileFormat object with Arrow-style null_values option
format <- CsvFileFormat$create(convert_options = list(null_values = c("", "NA", "NULL")))
open_dataset(tf, format = format)
#> FileSystemDataset with 1 csv file
#> 1 columns
#> x: int64
# Use readr-style options
format <- CsvFileFormat$create(na = c("", "NA", "NULL"))
open_dataset(tf, format = format)
#> FileSystemDataset with 1 csv file
#> 1 columns
#> x: int64