Skip to content

Commit

Permalink
fix bug in matlab import and printing of matlab import (closes #171)
Browse files Browse the repository at this point in the history
  • Loading branch information
leeper committed May 14, 2018
1 parent e66639a commit 1cc8854
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 5 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# rio 0.5.11

* Fixed a bug in `import()` wherein matlab files were ignored unless `format` was specified, as well as a related bug that made importing appear to fail for matlab files. (#171)
* Fixed a bug in `export()` wherein `format` was ignored. (#99, h/t Sebastian Sauer)
* Fixed a bug in the importing of European-style semicolon-separated CSV files. Added a test to ensure correct behavior. (#159, h/t Kenneth Rose)
* Updated documentation to reflect recent changes to the xlsx `export()` method. (#156)
Expand Down
6 changes: 4 additions & 2 deletions R/import.R
Original file line number Diff line number Diff line change
Expand Up @@ -112,18 +112,20 @@ import <- function(file, format, setclass, which, ...) {
if (fmt %in% c("gz", "gzip")) {
fmt <- file_ext(file_path_sans_ext(file, compression = FALSE))
file <- gzfile(file)
} else {
fmt <- get_type(fmt)
}
} else {
fmt <- get_type(format)
}

class(file) <- c(paste0("rio_", fmt), class(file))
if (missing(which)) {
x <- .import(file = file, ...)
} else {
x <- .import(file = file, which = which, ...)
}

a <- list(...)
if (missing(setclass) || is.null(setclass)) {
if ("data.table" %in% names(a) && isTRUE(a[["data.table"]])) {
Expand Down
7 changes: 6 additions & 1 deletion R/set_class.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,10 @@ set_class <- function(x, class = NULL) {
}
return(tibble::as_tibble(x))
}
return(structure(x, class = "data.frame"))
out <- structure(x, class = "data.frame")
# add row names in case `x` wasn't already a data frame (e.g., matlab list)
if (!length(rownames(out))) {
rownames(out) <- as.character(seq_len(length(out[,1L,drop = TRUE])))
}
return(out)
}
2 changes: 0 additions & 2 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,6 @@ get_type <- function(fmt) {
gnumeric = "gnumeric",
jpeg = "jpg",
jpg = "jpg",
mat = "matlab",
matlab = "matlab",
npy = "npy",
png = "png",
sdmx = "sdmx",
Expand Down
1 change: 1 addition & 0 deletions tests/testthat/test_format_matlab.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ if (requireNamespace("rmatio")) {

test_that("Import from matlab", {
expect_true(is.data.frame(import("iris.matlab")))
expect_true(identical(dim(import("iris.matlab")), dim(iris)))
})
unlink("iris.matlab")
}

0 comments on commit 1cc8854

Please sign in to comment.