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

'.import.rio_rdata()' and 'import.rio_rds()' no longer passing '...' … #229

Merged
merged 1 commit into from
Oct 2, 2019
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
10 changes: 8 additions & 2 deletions R/import_methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,10 @@ function(file,

#' @export
.import.rio_rds <- function(file, which = 1, ...) {
readRDS(file = file, ...)
if (length(list(...))>0) {
warning("File imported using readRDS. Arguments to '...' ignored.")
}
readRDS(file = file)
}

#' @export
Expand All @@ -155,7 +158,10 @@ function(file,

#' @export
.import.rio_rdata <- function(file, which = 1, envir = new.env(), ...) {
load(file = file, envir = envir, ...)
load(file = file, envir = envir)
if (length(list(...))>0) {
warning("File imported using load. Arguments to '...' ignored.")
}
if (missing(which)) {
if (length(ls(envir)) > 1) {
warning("Rdata file contains multiple objects. Returning first object.")
Expand Down
10 changes: 10 additions & 0 deletions tests/testthat/test_format_rdata.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ test_that("Export to Rdata", {
test_that("Import from Rdata", {
expect_true(is.data.frame(import("iris.Rdata")))
expect_true(is.data.frame(import("iris.Rdata", which = 1)))
expect_warning(is.data.frame(import("iris.Rdata",which=1,
verbose='ignored value',
invalid_argument=42)),
"File imported using load. Arguments to '...' ignored.",
label="RData imports and ignores unused arguments with a warning")
})

test_that("Export to rda", {
Expand All @@ -26,6 +31,11 @@ test_that("Export to rda", {
test_that("Import from rda", {
expect_true(is.data.frame(import("iris.rda")))
expect_true(is.data.frame(import("iris.rda", which = 1)))
expect_warning(is.data.frame(import("iris.rda", which=1,
verbose="ignored value",
invalid_argument=42)),
"File imported using load. Arguments to '...' ignored.",
label="rda imports and ignores unused arguments with a warning")
})

unlink("iris.Rdata")
Expand Down
3 changes: 3 additions & 0 deletions tests/testthat/test_format_rds.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ test_that("Export to rds", {

test_that("Import from rds", {
expect_true(is.data.frame(import("iris.rds")))
expect_warning(import("iris.rds", invalid_argument=42),
"File imported using readRDS. Arguments to '...' ignored.",
label="rda imports and ignores unused arguments with a warning")
})

test_that("Export to rds (non-data frame)", {
Expand Down