From 3b34e0cb28dfc3f84254c9cd68c8dc0ebffd314b Mon Sep 17 00:00:00 2001 From: "Sang T. Truong" Date: Sun, 1 Aug 2021 16:56:20 -0400 Subject: [PATCH 1/5] Adapt unittest for read_txt_Renishaw() function --- R/read_txt_Renishaw.R | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/R/read_txt_Renishaw.R b/R/read_txt_Renishaw.R index a565035..1860ce1 100644 --- a/R/read_txt_Renishaw.R +++ b/R/read_txt_Renishaw.R @@ -164,48 +164,47 @@ read_txt_Renishaw <- function(file = stop("file is required"), hySpc.testthat::test(read_txt_Renishaw) <- function() { context("read_txt_Renishaw") + path <- system.file("extdata/fileio/txt.Renishaw", package="hySpc.read.txt") + paracetamol <- paste0(path, "/paracetamol.txt") + laser <- paste0(path, "/laser.txt.gz") + chondro <- paste0(path, "/chondro.txt") test_that("single spectrum", { - skip("TODO: adapt to new package") - tmp <- read_txt_Renishaw("fileio/txt.Renishaw/paracetamol.txt", "spc") + tmp <- read_txt_Renishaw(paracetamol, "spc") expect_equal(dim(tmp), c(nrow = 1L, ncol = 2L, nwl = 4064L)) }) test_that("time series spectrum, gzipped", { - skip("TODO: adapt to new package") - tmp <- read_txt_Renishaw("fileio/txt.Renishaw/laser.txt.gz", "ts") + tmp <- read_txt_Renishaw(laser, "ts") expect_equal(dim(tmp), c(nrow = 84L, ncol = 3L, nwl = 140L)) expect_equal(colnames(tmp), c("t", "spc", "filename")) }) test_that("map (= default)", { - skip("TODO: adapt to new package") - tmp <- read_txt_Renishaw("fileio/txt.Renishaw/chondro.txt", "xyspc") + tmp <- read_txt_Renishaw(chondro, "xyspc") expect_equal(dim(tmp), c(nrow = 875L, ncol = 4L, nwl = 1272L)) expect_equal(colnames(tmp), c("y", "x", "spc", "filename")) - tmp <- read_txt_Renishaw("fileio/txt.Renishaw/chondro.txt") + tmp <- read_txt_Renishaw(chondro) expect_equal(dim(tmp), c(nrow = 875L, ncol = 4L, nwl = 1272L)) expect_equal(colnames(tmp), c("y", "x", "spc", "filename")) }) test_that("chunked reading", { - skip("TODO: adapt to new package") ## error on too small chunk size expect_error( - read_txt_Renishaw("fileio/txt.Renishaw/chondro.txt", nlines = 10), + read_txt_Renishaw(chondro, nlines = 10), "Wavelengths do not correspond" ) - tmp <- read_txt_Renishaw("fileio/txt.Renishaw/chondro.txt", nlines = 1e5) + tmp <- read_txt_Renishaw(chondro, nlines = 1e5) expect_equal(dim(tmp), c(nrow = 875L, ncol = 4L, nwl = 1272L)) }) test_that("compressed files", { - skip("TODO: adapt to new package") - files <- Sys.glob("fileio/txt.Renishaw/chondro.*") + files <- Sys.glob(paste0(path, "/chondro.*")) files <- grep("[.]zip", files, invert = TRUE, value = TRUE) # .zip is tested with read_zip_Renishaw for (f in files) { expect_equal(dim(read_txt_Renishaw(!!f)), c(nrow = 875L, ncol = 4L, nwl = 1272L)) From 9d027536674f0ad313e5536dd51a921d0820e42c Mon Sep 17 00:00:00 2001 From: "Sang T. Truong" Date: Fri, 6 Aug 2021 10:53:50 -0400 Subject: [PATCH 2/5] replace chondro with faux_cell --- R/read_txt_Renishaw.R | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/R/read_txt_Renishaw.R b/R/read_txt_Renishaw.R index 1860ce1..dda8f35 100644 --- a/R/read_txt_Renishaw.R +++ b/R/read_txt_Renishaw.R @@ -181,11 +181,11 @@ hySpc.testthat::test(read_txt_Renishaw) <- function() { }) test_that("map (= default)", { - tmp <- read_txt_Renishaw(chondro, "xyspc") + tmp <- read_txt_Renishaw(faux_cell, "xyspc") expect_equal(dim(tmp), c(nrow = 875L, ncol = 4L, nwl = 1272L)) expect_equal(colnames(tmp), c("y", "x", "spc", "filename")) - tmp <- read_txt_Renishaw(chondro) + tmp <- read_txt_Renishaw(faux_cell) expect_equal(dim(tmp), c(nrow = 875L, ncol = 4L, nwl = 1272L)) expect_equal(colnames(tmp), c("y", "x", "spc", "filename")) }) @@ -194,17 +194,17 @@ hySpc.testthat::test(read_txt_Renishaw) <- function() { ## error on too small chunk size expect_error( - read_txt_Renishaw(chondro, nlines = 10), + read_txt_Renishaw(faux_cell, nlines = 10), "Wavelengths do not correspond" ) - tmp <- read_txt_Renishaw(chondro, nlines = 1e5) + tmp <- read_txt_Renishaw(faux_cell, nlines = 1e5) expect_equal(dim(tmp), c(nrow = 875L, ncol = 4L, nwl = 1272L)) }) test_that("compressed files", { - files <- Sys.glob(paste0(path, "/chondro.*")) + files <- Sys.glob(paste0(path, "/faux_cell.*")) files <- grep("[.]zip", files, invert = TRUE, value = TRUE) # .zip is tested with read_zip_Renishaw for (f in files) { expect_equal(dim(read_txt_Renishaw(!!f)), c(nrow = 875L, ncol = 4L, nwl = 1272L)) @@ -238,7 +238,7 @@ hySpc.testthat::test(read_zip_Renishaw) <- function() { skip("TODO: adapt to new package") expect_equal( - dim(read_zip_Renishaw("fileio/txt.Renishaw/chondro.zip")), + dim(read_zip_Renishaw("fileio/txt.Renishaw/faux_cell.zip")), c(nrow = 875L, ncol = 4L, nwl = 1272L) ) }) From e2449b2354ceda7279d5399ee495adc756ac450d Mon Sep 17 00:00:00 2001 From: "Sang T. Truong" Date: Fri, 6 Aug 2021 11:44:36 -0400 Subject: [PATCH 3/5] fix path, return to chondro since can't file faux_cell --- R/read_txt_Renishaw.R | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/R/read_txt_Renishaw.R b/R/read_txt_Renishaw.R index dda8f35..494afdf 100644 --- a/R/read_txt_Renishaw.R +++ b/R/read_txt_Renishaw.R @@ -164,10 +164,10 @@ read_txt_Renishaw <- function(file = stop("file is required"), hySpc.testthat::test(read_txt_Renishaw) <- function() { context("read_txt_Renishaw") - path <- system.file("extdata/fileio/txt.Renishaw", package="hySpc.read.txt") + path <- system.file("extdata", "txt.Renishaw", package = "hySpc.read.txt") paracetamol <- paste0(path, "/paracetamol.txt") laser <- paste0(path, "/laser.txt.gz") - chondro <- paste0(path, "/chondro.txt") + faux_cell <- paste0(path, "/chondro.txt") test_that("single spectrum", { tmp <- read_txt_Renishaw(paracetamol, "spc") @@ -204,7 +204,7 @@ hySpc.testthat::test(read_txt_Renishaw) <- function() { test_that("compressed files", { - files <- Sys.glob(paste0(path, "/faux_cell.*")) + files <- Sys.glob(paste0(path, "/chondro.*")) files <- grep("[.]zip", files, invert = TRUE, value = TRUE) # .zip is tested with read_zip_Renishaw for (f in files) { expect_equal(dim(read_txt_Renishaw(!!f)), c(nrow = 875L, ncol = 4L, nwl = 1272L)) @@ -238,7 +238,7 @@ hySpc.testthat::test(read_zip_Renishaw) <- function() { skip("TODO: adapt to new package") expect_equal( - dim(read_zip_Renishaw("fileio/txt.Renishaw/faux_cell.zip")), + dim(read_zip_Renishaw("fileio/txt.Renishaw/chondro.zip")), c(nrow = 875L, ncol = 4L, nwl = 1272L) ) }) From 07c2c9cc94bde1fe4f543151cf048c977cf514ec Mon Sep 17 00:00:00 2001 From: "Sang T. Truong" Date: Fri, 6 Aug 2021 12:22:57 -0400 Subject: [PATCH 4/5] rename chondro to chondro_file to avoid confusion --- R/read_txt_Renishaw.R | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/R/read_txt_Renishaw.R b/R/read_txt_Renishaw.R index 494afdf..4ffc26c 100644 --- a/R/read_txt_Renishaw.R +++ b/R/read_txt_Renishaw.R @@ -167,7 +167,7 @@ hySpc.testthat::test(read_txt_Renishaw) <- function() { path <- system.file("extdata", "txt.Renishaw", package = "hySpc.read.txt") paracetamol <- paste0(path, "/paracetamol.txt") laser <- paste0(path, "/laser.txt.gz") - faux_cell <- paste0(path, "/chondro.txt") + chondro_file <- paste0(path, "/chondro.txt") test_that("single spectrum", { tmp <- read_txt_Renishaw(paracetamol, "spc") @@ -181,11 +181,11 @@ hySpc.testthat::test(read_txt_Renishaw) <- function() { }) test_that("map (= default)", { - tmp <- read_txt_Renishaw(faux_cell, "xyspc") + tmp <- read_txt_Renishaw(chondro_file, "xyspc") expect_equal(dim(tmp), c(nrow = 875L, ncol = 4L, nwl = 1272L)) expect_equal(colnames(tmp), c("y", "x", "spc", "filename")) - tmp <- read_txt_Renishaw(faux_cell) + tmp <- read_txt_Renishaw(chondro_file) expect_equal(dim(tmp), c(nrow = 875L, ncol = 4L, nwl = 1272L)) expect_equal(colnames(tmp), c("y", "x", "spc", "filename")) }) @@ -194,11 +194,11 @@ hySpc.testthat::test(read_txt_Renishaw) <- function() { ## error on too small chunk size expect_error( - read_txt_Renishaw(faux_cell, nlines = 10), + read_txt_Renishaw(chondro_file, nlines = 10), "Wavelengths do not correspond" ) - tmp <- read_txt_Renishaw(faux_cell, nlines = 1e5) + tmp <- read_txt_Renishaw(chondro_file, nlines = 1e5) expect_equal(dim(tmp), c(nrow = 875L, ncol = 4L, nwl = 1272L)) }) From e5613f3e217f09ae0620b66d197bf5d291695bd6 Mon Sep 17 00:00:00 2001 From: "Sang T. Truong" Date: Fri, 6 Aug 2021 12:37:04 -0400 Subject: [PATCH 5/5] rename object name with prefix f_ --- R/read_txt_Renishaw.R | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/R/read_txt_Renishaw.R b/R/read_txt_Renishaw.R index 4ffc26c..56bedb9 100644 --- a/R/read_txt_Renishaw.R +++ b/R/read_txt_Renishaw.R @@ -165,27 +165,27 @@ read_txt_Renishaw <- function(file = stop("file is required"), hySpc.testthat::test(read_txt_Renishaw) <- function() { context("read_txt_Renishaw") path <- system.file("extdata", "txt.Renishaw", package = "hySpc.read.txt") - paracetamol <- paste0(path, "/paracetamol.txt") - laser <- paste0(path, "/laser.txt.gz") - chondro_file <- paste0(path, "/chondro.txt") + f_paracetamol <- paste0(path, "/paracetamol.txt") + f_laser <- paste0(path, "/laser.txt.gz") + f_chondro <- paste0(path, "/chondro.txt") test_that("single spectrum", { - tmp <- read_txt_Renishaw(paracetamol, "spc") + tmp <- read_txt_Renishaw(f_paracetamol, "spc") expect_equal(dim(tmp), c(nrow = 1L, ncol = 2L, nwl = 4064L)) }) test_that("time series spectrum, gzipped", { - tmp <- read_txt_Renishaw(laser, "ts") + tmp <- read_txt_Renishaw(f_laser, "ts") expect_equal(dim(tmp), c(nrow = 84L, ncol = 3L, nwl = 140L)) expect_equal(colnames(tmp), c("t", "spc", "filename")) }) test_that("map (= default)", { - tmp <- read_txt_Renishaw(chondro_file, "xyspc") + tmp <- read_txt_Renishaw(f_chondro, "xyspc") expect_equal(dim(tmp), c(nrow = 875L, ncol = 4L, nwl = 1272L)) expect_equal(colnames(tmp), c("y", "x", "spc", "filename")) - tmp <- read_txt_Renishaw(chondro_file) + tmp <- read_txt_Renishaw(f_chondro) expect_equal(dim(tmp), c(nrow = 875L, ncol = 4L, nwl = 1272L)) expect_equal(colnames(tmp), c("y", "x", "spc", "filename")) }) @@ -194,11 +194,11 @@ hySpc.testthat::test(read_txt_Renishaw) <- function() { ## error on too small chunk size expect_error( - read_txt_Renishaw(chondro_file, nlines = 10), + read_txt_Renishaw(f_chondro, nlines = 10), "Wavelengths do not correspond" ) - tmp <- read_txt_Renishaw(chondro_file, nlines = 1e5) + tmp <- read_txt_Renishaw(f_chondro, nlines = 1e5) expect_equal(dim(tmp), c(nrow = 875L, ncol = 4L, nwl = 1272L)) })