From 513b261432b23d4cea939e3df312988f104b2242 Mon Sep 17 00:00:00 2001 From: Andrea Ranzato Date: Sun, 9 Jun 2024 20:28:57 +0200 Subject: [PATCH 1/2] default to 'free' format if not given --- R/import.spc.R | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/R/import.spc.R b/R/import.spc.R index 9537455..f9cc87e 100644 --- a/R/import.spc.R +++ b/R/import.spc.R @@ -178,6 +178,10 @@ print.import.spc <- function(x, ...){ ext_ser_call <- function(spc, vname){ if (is.null(spc)) return(NULL) + + # the default data format for X-13 is "free" + fformat <- ifelse(is.null(spc$format), "free", spc$format) + frm <- rem_quotes(fformat) # analyze series spec if ("data" %in% names(spc)){ @@ -190,9 +194,7 @@ ext_ser_call <- function(spc, vname){ ", start = ", deparse(start), ", frequency = ", f, ")") } else if ("file" %in% names(spc)){ - - frm <- rem_quotes(spc$format) - + # fragment for name, for fortran and x11 series if (!is.null(spc$name)) { nm <- rem_quotes(spc$name) From 07ae6c4a9144b7cabf58876cc3820047cb735372 Mon Sep 17 00:00:00 2001 From: Andrea Ranzato Date: Mon, 10 Jun 2024 09:01:31 +0200 Subject: [PATCH 2/2] test ext_ser_call() --- tests/testthat/_snaps/ext_ser_call.md | 14 ++++++++++++ tests/testthat/test-ext_ser_call.R | 32 +++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 tests/testthat/_snaps/ext_ser_call.md create mode 100644 tests/testthat/test-ext_ser_call.R diff --git a/tests/testthat/_snaps/ext_ser_call.md b/tests/testthat/_snaps/ext_ser_call.md new file mode 100644 index 0000000..4ead03e --- /dev/null +++ b/tests/testthat/_snaps/ext_ser_call.md @@ -0,0 +1,14 @@ +# ext_ser_call() + + Code + ext_ser_call(pp, "x") + Output + [1] "x <- import.ts(file.dat)" + +# ext_ser_call() defaults to format "free" + + Code + ext_ser_call(pp, "x") + Output + [1] "x <- import.ts(file.dat, format = \"free\", start = c(2014, 1), frequency = 12, name = \"xyz\")" + diff --git a/tests/testthat/test-ext_ser_call.R b/tests/testthat/test-ext_ser_call.R new file mode 100644 index 0000000..9829d65 --- /dev/null +++ b/tests/testthat/test-ext_ser_call.R @@ -0,0 +1,32 @@ +test_that("ext_ser_call()", { + + pp <- list( + title = "abc", + start = 2014.01, + period = 12, + save = c("a1", "b1"), + print = "brief", + format = "datevalue", + name = "xyz", + file = "file.dat" + ) + + expect_snapshot(ext_ser_call(pp, "x")) + +}) + +test_that("ext_ser_call() defaults to format \"free\"", { + + pp <- list( + title = "abc", + start = 2014.01, + period = 12, + save = c("a1", "b1"), + print = "brief", + name = "xyz", + file = "file.dat" + ) + + expect_snapshot(ext_ser_call(pp, "x")) + +})