Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #430 #431

Merged
merged 1 commit into from
Jun 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# rio 1.1.1.999 (development)

Bug fixes

* Fix #430 Add back support for `.dat`

# rio 1.1.1

Bus fixes
Bug fixes

* Fix #425 for archive formats, the file extension of the input file is determined by the compressed file (like prior rio 1.1.0)

Expand Down
2 changes: 1 addition & 1 deletion R/import_methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import_delim <- function(file, which = 1, sep = "auto", header = "auto", strings

#' @export
.import.rio_dat <- function(file, which = 1, ...) {
message(sprintf("Ambiguous file format ('.dat'), but attempting 'data.table::fread(\"%s\")'", file))
message(sprintf("Ambiguous file format ('.dat'), but attempting 'data.table::fread(\"%s\")'\n", file))
import_delim(file = file, ...)
}

Expand Down
Binary file modified R/sysdata.rda
Binary file not shown.
93 changes: 47 additions & 46 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,52 +126,53 @@ install_formats()

The full list of supported formats is below:

| Name | Extensions / “format” | Import Package | Export Package | Type | Note |
| :---------------------------------- | :---------------------------------- | :------------- | :------------- | :------ | :---------------------- |
| Archive files (handled by tar) | tar / tar.gz / tgz / tar.bz2 / tbz2 | utils | utils | Default | |
| Bzip2 | bz2 / bzip2 | base | base | Default | |
| Gzip | gz / gzip | base | base | Default | |
| Zip files | zip | utils | utils | Default | |
| CSVY (CSV + YAML metadata header) | csvy | data.table | data.table | Default | |
| Comma-separated data | csv | data.table | data.table | Default | |
| Comma-separated data (European) | csv2 | data.table | data.table | Default | |
| Data Interchange Format | dif | utils | | Default | |
| Epiinfo | epiinfo / rec | foreign | | Default | |
| Excel | excel / xlsx | readxl | writexl | Default | |
| Excel (Legacy) | xls | readxl | | Default | |
| Fixed-width format data | fwf | readr | utils | Default | |
| Fortran data | fortran | utils | | Default | No recognized extension |
| Google Sheets | googlesheets | data.table | | Default | As comma-separated data |
| Minitab | minitab / mtp | foreign | | Default | |
| Pipe-separated data | psv | data.table | data.table | Default | |
| R syntax | r | base | base | Default | |
| SAS | sas / sas7bdat | haven | haven | Default | Export is deprecated |
| SAS XPORT | xport / xpt | haven | haven | Default | |
| SPSS | sav / spss | haven | haven | Default | |
| SPSS (compressed) | zsav | haven | haven | Default | |
| SPSS Portable | por | haven | | Default | |
| Saved R objects | rda / rdata | base | base | Default | |
| Serialized R objects | rds | base | base | Default | |
| Stata | dta / stata | haven | haven | Default | |
| Systat | syd / systat | foreign | | Default | |
| Tab-separated data | / tsv / txt | data.table | data.table | Default | |
| Text Representations of R Objects | dump | base | base | Default | |
| Weka Attribute-Relation File Format | arff / weka | foreign | foreign | Default | |
| XBASE database files | dbf | foreign | foreign | Default | |
| Apache Arrow (Parquet) | parquet | arrow | arrow | Suggest | |
| Clipboard | clipboard | clipr | clipr | Suggest | default is tsv |
| EViews | eviews / wf1 | hexView | | Suggest | |
| Fast Storage | fst | fst | fst | Suggest | |
| Feather R/Python interchange format | feather | arrow | arrow | Suggest | |
| Graphpad Prism | pzfx | pzfx | pzfx | Suggest | |
| HTML Tables | htm / html | xml2 | xml2 | Suggest | |
| JSON | json | jsonlite | jsonlite | Suggest | |
| Matlab | mat / matlab | rmatio | rmatio | Suggest | |
| OpenDocument Spreadsheet | ods | readODS | readODS | Suggest | |
| OpenDocument Spreadsheet (Flat) | fods | readODS | readODS | Suggest | |
| Serialized R objects (Quick) | qs | qs | qs | Suggest | |
| Shallow XML documents | xml | xml2 | xml2 | Suggest | |
| YAML | yaml / yml | yaml | yaml | Suggest | |
| Name | Extensions / “format” | Import Package | Export Package | Type | Note |
| :---------------------------------- | :---------------------------------- | :------------- | :------------- | :------ | :----------------------------- |
| Archive files (handled by tar) | tar / tar.gz / tgz / tar.bz2 / tbz2 | utils | utils | Default | |
| Bzip2 | bz2 / bzip2 | base | base | Default | |
| Gzip | gz / gzip | base | base | Default | |
| Zip files | zip | utils | utils | Default | |
| Ambiguous file format | dat | data.table | | Default | Attempt as delimited text data |
| CSVY (CSV + YAML metadata header) | csvy | data.table | data.table | Default | |
| Comma-separated data | csv | data.table | data.table | Default | |
| Comma-separated data (European) | csv2 | data.table | data.table | Default | |
| Data Interchange Format | dif | utils | | Default | |
| Epiinfo | epiinfo / rec | foreign | | Default | |
| Excel | excel / xlsx | readxl | writexl | Default | |
| Excel (Legacy) | xls | readxl | | Default | |
| Fixed-width format data | fwf | readr | utils | Default | |
| Fortran data | fortran | utils | | Default | No recognized extension |
| Google Sheets | googlesheets | data.table | | Default | As comma-separated data |
| Minitab | minitab / mtp | foreign | | Default | |
| Pipe-separated data | psv | data.table | data.table | Default | |
| R syntax | r | base | base | Default | |
| SAS | sas / sas7bdat | haven | haven | Default | Export is deprecated |
| SAS XPORT | xport / xpt | haven | haven | Default | |
| SPSS | sav / spss | haven | haven | Default | |
| SPSS (compressed) | zsav | haven | haven | Default | |
| SPSS Portable | por | haven | | Default | |
| Saved R objects | rda / rdata | base | base | Default | |
| Serialized R objects | rds | base | base | Default | |
| Stata | dta / stata | haven | haven | Default | |
| Systat | syd / systat | foreign | | Default | |
| Tab-separated data | / tsv / txt | data.table | data.table | Default | |
| Text Representations of R Objects | dump | base | base | Default | |
| Weka Attribute-Relation File Format | arff / weka | foreign | foreign | Default | |
| XBASE database files | dbf | foreign | foreign | Default | |
| Apache Arrow (Parquet) | parquet | arrow | arrow | Suggest | |
| Clipboard | clipboard | clipr | clipr | Suggest | default is tsv |
| EViews | eviews / wf1 | hexView | | Suggest | |
| Fast Storage | fst | fst | fst | Suggest | |
| Feather R/Python interchange format | feather | arrow | arrow | Suggest | |
| Graphpad Prism | pzfx | pzfx | pzfx | Suggest | |
| HTML Tables | htm / html | xml2 | xml2 | Suggest | |
| JSON | json | jsonlite | jsonlite | Suggest | |
| Matlab | mat / matlab | rmatio | rmatio | Suggest | |
| OpenDocument Spreadsheet | ods | readODS | readODS | Suggest | |
| OpenDocument Spreadsheet (Flat) | fods | readODS | readODS | Suggest | |
| Serialized R objects (Quick) | qs | qs | qs | Suggest | |
| Shallow XML documents | xml | xml2 | xml2 | Suggest | |
| YAML | yaml / yml | yaml | yaml | Suggest | |

Additionally, any format that is not supported by **rio** but that has a
known R implementation will produce an informative error message
Expand Down
9 changes: 9 additions & 0 deletions data-raw/single.json
Original file line number Diff line number Diff line change
Expand Up @@ -781,6 +781,15 @@
"import_function": "data.table::fread",
"export_function": "data.table::fwrite",
"note": ""
},
{
"input": "dat",
"format": "dat",
"type": "import",
"format_name": "Ambiguous file format",
"import_function": "data.table::fread",
"export_function": "",
"note": "Attempt as delimited text data"
}
]

10 changes: 10 additions & 0 deletions tests/testthat/test_format_csv.R
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,13 @@ test_that("fread is deprecated", {
lifecycle::expect_deprecated(import(iris_file, fread = FALSE))
})
})

test_that("dat (ambiguous file format) will be attempted #430", {
withr::with_tempfile("iris_file", fileext = ".dat", code = {
readr::write_delim(iris, file = iris_file)
expect_error(suppressMessages(import(iris_file)), NA)
expect_message(z <- import(iris_file))
## export is not supported though
expect_error(export(iris, iris_file))
})
})
Loading