From 3f46e31cae70f43588b2cd8bcf0beaf0b5a54d0c Mon Sep 17 00:00:00 2001 From: Daniel Date: Sat, 12 Oct 2024 09:05:22 +0200 Subject: [PATCH] set `trust = TRUE` also for RData files (#557) * set `trust = TRUE` also for RData files * fix test * lintr --- DESCRIPTION | 2 +- NEWS.md | 3 +++ R/data_read.R | 4 ++-- tests/testthat/test-data_read.R | 13 +++++++++++++ 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 841bb2573..cc9810def 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Type: Package Package: datawizard Title: Easy Data Wrangling and Statistical Transformations -Version: 0.13.0.7 +Version: 0.13.0.8 Authors@R: c( person("Indrajeet", "Patil", , "patilindrajeet.science@gmail.com", role = "aut", comment = c(ORCID = "0000-0003-1995-6531")), diff --git a/NEWS.md b/NEWS.md index 679a71a9c..b5cdf84c0 100644 --- a/NEWS.md +++ b/NEWS.md @@ -16,6 +16,9 @@ CHANGES * New function `row_count()`, to count specific values row-wise. +* `data_read()` no longer shows warning about forthcoming breaking changes + in upstream packages when reading `.RData` files. + BUG FIXES * `describe_distribution()` no longer errors if the sample was too sparse to compute diff --git a/R/data_read.R b/R/data_read.R index 5137a7735..1306a3f32 100644 --- a/R/data_read.R +++ b/R/data_read.R @@ -161,7 +161,7 @@ data_read <- function(path, # user may decide whether we automatically detect variable type or not if (isTRUE(convert_factors)) { if (verbose) { - msg <- "Variables where all values have associated labels are now converted into factors. If this is not intended, use `convert_factors = FALSE`." + msg <- "Variables where all values have associated labels are now converted into factors. If this is not intended, use `convert_factors = FALSE`." # nolint insight::format_alert(msg) } x[] <- lapply(x, function(i) { @@ -296,7 +296,7 @@ data_read <- function(path, # set up arguments. for RDS, we set trust = TRUE, to avoid warnings rio_args <- list(file = path) # check if we have RDS, and if so, add trust = TRUE - if (file_type == "rds") { + if (file_type %in% c("rds", "rdata")) { rio_args$trust <- TRUE } out <- do.call(rio::import, c(rio_args, list(...))) diff --git a/tests/testthat/test-data_read.R b/tests/testthat/test-data_read.R index fd4884deb..ac316c706 100644 --- a/tests/testthat/test-data_read.R +++ b/tests/testthat/test-data_read.R @@ -154,6 +154,19 @@ test_that("data_read - RDS file, matrix, coercible", { }) + +# RData ----------------------------------- + +test_that("data_read - no warning for RData", { + withr::with_tempfile("temp_file", fileext = ".RData", code = { + data(mtcars) + save(mtcars, file = temp_file) + expect_silent(data_read(temp_file, verbose = FALSE)) + }) +}) + + + # SPSS file ----------------------------------- test_that("data_read - SPSS file", {