跳到內容

CSVFileFormatFileFormat 的子類別,它包含了如何讀取和解析 CSV Dataset 中檔案的資訊。

一個 CsvFileFormat 物件

工廠

CSVFileFormat$create() 可以接受選項,選項的形式為列表,以 parse_optionsread_optionsconvert_options 參數傳遞。或者,readr 風格的選項可以個別傳遞。雖然可以傳入 CSVReadOptionsCSVConvertOptionsCSVParseOptions 物件,但不建議這樣做,因為在這些物件中設定的選項未經驗證其相容性。

另請參閱

範例

# 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