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 bmp import typo. Add import notes for ledger package. #190

Merged
merged 4 commits into from
Nov 25, 2018
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
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ Authors@R: c(person("Jason", "Becker", role = "ctb", email = "jason@jbecker.co")
person("Stanislaus", "Stadlmann", role = "ctb"),
person("Ruaridh", "Williamson", role = "ctb", email = "ruaridh.williamson@gmail.com"),
person("Patrick", "Kennedy", role = "ctb"),
person("Ryan", "Price", email = "ryapric@gmail.com", role = "ctb"))
person("Ryan", "Price", email = "ryapric@gmail.com", role = "ctb"),
person("Trevor L", "Davis", email = "trevor.l.davis@gmail.com", role = "ctb"))
Description: Streamlined data import and export by making assumptions that
the user is probably willing to make: 'import()' and 'export()' determine
the data structure from the file extension, reasonable defaults are used for
Expand Down
15 changes: 10 additions & 5 deletions R/extensions.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,24 @@
#' @export
.import.default <- function(file, ...){
x <- gettext("%s format not supported. Consider using the '%s()' function")
xA <- gettext("Import support for the %s format is exported by the %s package. Run 'library(%s)' then try again.")
fmt <- tools::file_ext(file)
out <- switch(fmt,
bean = sprintf(xA, fmt, "ledger", "ledger"),
beancount = sprintf(xA, fmt, "ledger", "ledger"),
bib = sprintf(x, fmt, "bib2df::bib2df"),
bmp = sprintf(x, fmt, "bmp::read.bmp"),
gexf = sprintf(x, fmt, "rgexf::read.gexf"),
gnumeric = sprintf(x, fmt, "gnumeric::read.gnumeric.sheet"),
hledger = sprintf(xA, fmt, "ledger", "ledger"),
jpeg = sprintf(x, fmt, "jpeg::readJPEG"),
jpg = sprintf(x, fmt, "jpeg::readJPEG"),
ledger = sprintf(xA, fmt, "ledger", "ledger"),
npy = sprintf(x, fmt, "RcppCNPy::npyLoad"),
png = sprintf(x, fmt, "png::readPNG"),
png = sprintf(x, fmt, "bmp::read.bmp"),
tiff = sprintf(x, fmt, "tiff::readTIFF"),
sss = sprintf(x, fmt, "sss::read.sss"),
sdmx = sprintf(x, fmt, "sdmx::readSDMX"),
gexf = sprintf(x, fmt, "rgexf::read.gexf"),
npy = sprintf(x, fmt, "RcppCNPy::npyLoad"),
sss = sprintf(x, fmt, "sss::read.sss"),
tiff = sprintf(x, fmt, "tiff::readTIFF"),
gettext("Format not supported"))
stop(out)
}
Expand Down
23 changes: 23 additions & 0 deletions tests/testthat/test_format_external_packages.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
context("External package Import/Export support")
require("datasets")

test_that("External read functions without an import method", {
extensions <- c("bib", "bmp", "gexf", "gnumeric", "jpeg", "jpg", "npy", "png", "sss", "sdmx", "tiff")
for (ext in extensions) {
file <- file.path(tempdir(), paste0("test.", ext))
file.create(file)
on.exit(unlink(file))
expect_error(import(file))
}
})

test_that("import method exported by an external package", {
extensions <- c("bean", "beancount", "ledger", "hledger")
for (ext in extensions) {
file <- file.path(tempdir(), paste0("test.", ext))
file.create(file)
on.exit(unlink(file))
expect_error(import(file))
}
})