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