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

Cran fixes #138

Merged
merged 19 commits into from
Sep 4, 2023
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
6 changes: 3 additions & 3 deletions CRAN-SUBMISSION
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Version: 1.0.0
Date: 2023-09-01 14:53:15 UTC
SHA: 1924ab057e7bd36723eccdd4649204fef0b2366c
Version: 1.0.1
Date: 2023-09-04 13:32:12 UTC
SHA: 0ae4952382c771ea3f729f1303fd6431182d7d95
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Package: OpenSpecy
Type: Package
Title: Analyze, Process, Identify, and Share Raman and (FT)IR Spectra
Version: 1.0.1
Date: 2023-09-01
Date: 2023-09-04
Authors@R: c(person("Win", "Cowger", role = c("cre", "aut", "dtc"),
email = "[email protected]",
comment = c(ORCID = "0000-0001-9226-3104")),
Expand Down
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
## Bug Fixes

- Fixed spelling mistakes
- Reduced example run time for CRAN
- Reduced example and test run times for CRAN


# OpenSpecy 1.0.0
Expand Down
10 changes: 5 additions & 5 deletions R/OpenSpecy-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
#' Infrared Spectroscopy.” \emph{Applied Spectroscopy}, \strong{74}(9),
#' 1167–1183. \doi{10.1177/0003702820923993}.
#'
#' Cowger W, Gray A, Christiansen SH, Christiansen SH, Christiansen SH,
#' De Frond H, Deshpande AD, Hemabessiere L, Lee E, Mill L, et al. (2020).
#' “Critical Review of Processing and Classification Techniques for Images and
#' Spectra in Microplastic Research.” \emph{Applied Spectroscopy},
#' \strong{74}(9), 989–1010. \doi{10.1177/0003702820929064}.
#' Cowger W, Gray A, Christiansen SH, De Frond H, Deshpande AD, Hemabessiere L,
#' Lee E, Mill L, et al. (2020). “Critical Review of Processing and
#' Classification Techniques for Images and Spectra in Microplastic Research.”
#' \emph{Applied Spectroscopy}, \strong{74}(9), 989–1010.
#' \doi{10.1177/0003702820929064}.
#'
#' Cowger, W (2021). “Library data.” \emph{OSF}. \doi{10.17605/OSF.IO/X7DPZ}.
#'
Expand Down
25 changes: 17 additions & 8 deletions R/interactive_plots.R
Original file line number Diff line number Diff line change
Expand Up @@ -76,35 +76,41 @@ plotly_spec.OpenSpecy <- function(x, x2 = NULL,
line2 = list(dash = "dot",
color = "rgb(255,0,0)"),
font = list(color = '#FFFFFF'),
plot_bgcolor = 'rgb(17, 0, 73)',
plot_bgcolor = 'rgba(17, 0, 73, 0)',
paper_bgcolor = 'rgb(0, 0, 0)',
...) {
x <- make_rel(x, na.rm = T)
dt <- cbind(wavenumber = x$wavenumber, x$spectra) |>
melt(id.vars = "wavenumber", variable.name = "id", value.name = "intensity")

p <- plot_ly(dt, type = "scatter", mode = "lines", ...) |>
add_trace(x = ~wavenumber, y = ~make_rel(intensity, na.rm = T),
color = ~id, line = line,
name = "x1", showlegend = F) |>
p <- plot_ly(dt, type = "scatter", mode = "lines") |>
add_trace(x = ~wavenumber,
y = ~intensity,
split = ~id,
line = line,
name = "x1",
showlegend = F) |>
layout(xaxis = list(title = "wavenumber [cm<sup>-1</sup>]",
autorange = "reversed"),
yaxis = list(title = "intensity [-]"),
plot_bgcolor = plot_bgcolor,
paper_bgcolor = paper_bgcolor,
legend = list(orientation = 'h', y = 1.1), font = font)
legend = list(orientation = 'h', y = 1.1),
font = font)

# Add dummy trace for Your Spectra
p <- p |>
add_trace(x = NULL, y = NULL,
line = line, name = "x1", showlegend = T)

if (!is.null(x2)) {
x2 <- make_rel(x2, na.rm = T)
dt2 <- cbind(wavenumber = x2$wavenumber, x2$spectra) |>
melt(id.vars = "wavenumber", variable.name = "id", value.name = "intensity")

p <- p |>
add_trace(data = dt2, x = ~wavenumber, y = ~make_rel(intensity, na.rm = T),
color = ~id, type = "scatter", mode = "lines",
add_trace(data = dt2, x = ~wavenumber, y = ~intensity,
split = ~id, type = "scatter", mode = "lines",
name = "x2",
line = line2, showlegend = F)

Expand Down Expand Up @@ -157,6 +163,9 @@ heatmap_spec.OpenSpecy <- function(x,
if (!is.null(cor) && !is.null(min_cor))
plot_z <- ifelse(cor > min_cor, plot_z, NA)

if(all(is.na(plot_z)))
plot_z = rep(-88, length.out = length(plot_z))

p <- plot_ly(...) |>
add_trace(x = x$metadata$x, y = x$metadata$y, z = if(!is.numeric(plot_z)){as.numeric(as.factor(plot_z))} else{plot_z},
colorscale = colorscale, type = "heatmap", hoverinfo = 'text',
Expand Down
10 changes: 5 additions & 5 deletions R/manage_lib.R
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@
#' Zacharias Steinmetz, Win Cowger
#'
#' @references
#' Cowger W, Gray A, Christiansen SH, Christiansen SH, Christiansen SH,
#' De Frond H, Deshpande AD, Hemabessiere L, Lee E, Mill L, et al. (2020).
#' “Critical Review of Processing and Classification Techniques for Images and
#' Spectra in Microplastic Research.” \emph{Applied Spectroscopy},
#' \strong{74}(9), 989–1010. \doi{10.1177/0003702820929064}.
#' Cowger W, Gray A, Christiansen SH, De Frond H, Deshpande AD, Hemabessiere L,
#' Lee E, Mill L, et al. (2020). “Critical Review of Processing and
#' Classification Techniques for Images and Spectra in Microplastic Research.”
#' \emph{Applied Spectroscopy}, \strong{74}(9), 989–1010.
#' \doi{10.1177/0003702820929064}.
#'
#' Cowger, W (2021). “Library data.” \emph{OSF}. \doi{10.17605/OSF.IO/X7DPZ}.
#'
Expand Down
11 changes: 2 additions & 9 deletions R/match_spec.R
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,6 @@
#' process_spec()
#' cor_spec(unknown, test_lib)
#'
#' test_lib_extract <- filter_spec(test_lib,
#' logic = grepl("polycarbonate", test_lib$metadata$polymer_class,
#' ignore.case = TRUE)
#' )
#'
#' cor_spec(unknown, library = test_lib_extract)
#'
#' match_spec(unknown, test_lib, add_library_metadata = "sample_name",
#' top_n = 1)
#'
Expand Down Expand Up @@ -154,9 +147,9 @@ match_spec.OpenSpecy <- function(x, library, na.rm = T, top_n = NULL,
}

if(!is.null(order)) {
.r <- NULL
.reorder <- NULL
match <- match(colnames(order$spectra), res$object_id)
setorder(res[, .r := order(match)], .r)[, .r := NULL]
setorder(res[, .reorder := order(match)], .reorder)[, .reorder := NULL]
}

return(res)
Expand Down
10 changes: 5 additions & 5 deletions R/raman_hdpe.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@
#' Zacharias Steinmetz, Win Cowger
#'
#' @references
#' Cowger W, Steinmetz Z, Gray A, Christiansen SH, Christiansen SH, Christiansen SH,
#' De Frond H, Deshpande AD, Hemabessiere L, Lee E, Mill L, et al. (2020).
#' “Critical Review of Processing and Classification Techniques for Images and
#' Spectra in Microplastic Research.” \emph{Applied Spectroscopy},
#' \strong{74}(9), 989–1010. \doi{10.1177/0003702820929064}.
#' Cowger W, Gray A, Christiansen SH, De Frond H, Deshpande AD, Hemabessiere L,
#' Lee E, Mill L, et al. (2020). “Critical Review of Processing and
#' Classification Techniques for Images and Spectra in Microplastic Research.”
#' \emph{Applied Spectroscopy}, \strong{74}(9), 989–1010.
#' \doi{10.1177/0003702820929064}.
#'
#' @docType data
#' @keywords data
Expand Down
10 changes: 5 additions & 5 deletions man/OpenSpecy-package.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/interactive_plots.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions man/manage_lib.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 0 additions & 7 deletions man/match_spec.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions man/raman_hdpe.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions tests/testthat/test-def_features.R
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ test_that("check that particles are identified with all TRUE or FALSE logical ve
})

test_that("the original spectrum remains unmodified and metadata is amended", {
skip_on_cran()

map <- read_extdata("CA_tiny_map.zip") |> read_any()

id_map <- def_features(map,ifelse(map$metadata$x == 1,
Expand All @@ -60,6 +62,8 @@ test_that("the original spectrum remains unmodified and metadata is amended", {
})

test_that("collapse particles returns expected values", {
skip_on_cran()

particles <- ifelse(map$metadata$y == 1, "particleA", "particleB")
id_map <- def_features(map, particles)
expect_true(check_OpenSpecy(id_map))
Expand Down
11 changes: 8 additions & 3 deletions tests/testthat/test-interactive_plots.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ test_that("plotly_spec() handles input errors correctly", {
})

test_that("plotly_spec() generates 'plotly' object", {
plotly_spec(raman_hdpe, select = 1) |>
plotly_spec(raman_hdpe) |>
expect_silent() |>
expect_s3_class("plotly")
})
Expand All @@ -21,8 +21,13 @@ test_that("heatmap_spec() generates 'plotly' object", {
expect_s3_class("plotly")
})

test_that("heatmap_spec() can handle all NA", {
heatmap_spec(map, z = map$metadata$y, sn = map$metadata$y, min_sn = 100) |>
expect_silent()
})

test_that("interactive_plot() generates 'plotly' object", {
interactive_plot(map, x2 = raman_hdpe, select = 2) |>
suppressWarnings() |>
interactive_plot(map, x2 = raman_hdpe, select = 2:3) |>
expect_silent() |>
expect_s3_class("plotly")
})
8 changes: 2 additions & 6 deletions tests/testthat/test-match_spec.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@ preproc <- conform_spec(unknown, range = test_lib$wavenumber,
res = spec_res(test_lib)) |>
process_spec(smooth_intens = T, make_rel = T)

# Create a subset of test_lib for filtering
test_lib_extract <- filter_spec(
test_lib, logic = test_lib$metadata$polymer_class == "polycarbonates"
)

test_that("ai_classify() handles input errors correctly", {
ai_classify(1:1000) |> expect_error()
})
Expand Down Expand Up @@ -43,7 +38,6 @@ test_that("match_spec() handles input errors correctly", {
match_spec(1:1000) |> expect_error()
})

# Match_spec function
test_that("match_spec() returns correct structure", {
matches <- match_spec(x = preproc, library = test_lib, na.rm = T, top_n = 5,
add_library_metadata = "sample_name",
Expand Down Expand Up @@ -74,6 +68,8 @@ test_that("cor_spec() handles input errors correctly", {

# Write the tests for cor_spec function
test_that("cor_spec() returns a data.table with correct columns", {
skip_on_cran()

matches <- cor_spec(preproc, library = test_lib) |>
expect_silent()

Expand Down
14 changes: 14 additions & 0 deletions tests/testthat/test-share_spec.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ data("raman_hdpe")
wo_meta <- raman_hdpe
wo_meta$metadata$spectrum_identity <- NULL

wo_sid <- raman_hdpe
wo_sid$metadata$session_id <- NULL

test_that("share_text() works locally", {
share_spec(raman_hdpe, file = read_extdata("raman_hdpe.csv"), share = tmp) |>
expect_message()
Expand All @@ -22,6 +25,9 @@ test_that("share_text() works locally", {
share_spec(wo_meta, share = tmp) |>
expect_message() |>
expect_warning()

share_spec(wo_sid, share = tmp) |>
expect_error()
})

test_that("share_text() uploads to the cloud", {
Expand All @@ -36,6 +42,14 @@ test_that("share_text() uploads to the cloud", {
s3_secret = Sys.getenv("AWS_SECRET_ACCESS_KEY"),
s3_region = "us-east-2", s3_bucket = "openspecy")) |>
expect_message()

share_spec(raman_hdpe, file = read_extdata("raman_hdpe.csv"), share = "cloud",
credentials = list(
s3_region = "us-east-2", s3_bucket = "openspecy")) |>
expect_error()

share_spec(raman_hdpe, file = read_extdata("raman_hdpe.csv"), share = "cloud") |>
expect_error()
})

# Tidy up
Expand Down
8 changes: 4 additions & 4 deletions vignettes/advanced.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,10 @@ Process for Identification of Microplastics Based on Fourier Transform Infrared
Spectroscopy.” *Applied Spectroscopy*, **74**(9), 1167–1183. doi:
[10.1177/0003702820923993](https://doi.org/10.1177/0003702820923993).

Cowger W, Gray A, Christiansen SH, Christiansen SH, Christiansen SH, De Frond H,
Deshpande AD, Hemabessiere L, Lee E, Mill L, et al. (2020). “Critical Review of
Processing and Classification Techniques for Images and Spectra in Microplastic
Research.” *Applied Spectroscopy*, **74**(9), 989–1010. doi:
Cowger W, Gray A, Christiansen SH, De Frond H, Deshpande AD, Hemabessiere L, Lee
E, Mill L, et al. (2020). “Critical Review of Processing and Classification
Techniques for Images and Spectra in Microplastic Research.” *Applied
Spectroscopy*, **74**(9), 989–1010. doi:
[10.1177/0003702820929064](https://doi.org/10.1177/0003702820929064).

Cowger W, Steinmetz Z, Gray A, Munno K, Lynch J, Hapich H, Primpke S,
Expand Down
8 changes: 4 additions & 4 deletions vignettes/app.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -406,10 +406,10 @@ Process for Identification of Microplastics Based on Fourier Transform Infrared
Spectroscopy.” *Applied Spectroscopy*, **74**(9), 1167–1183. doi:
[10.1177/0003702820923993](https://doi.org/10.1177/0003702820923993).

Cowger W, Gray A, Christiansen SH, Christiansen SH, Christiansen SH, De Frond H,
Deshpande AD, Hemabessiere L, Lee E, Mill L, et al. (2020). “Critical Review of
Processing and Classification Techniques for Images and Spectra in Microplastic
Research.” *Applied Spectroscopy*, **74**(9), 989–1010. doi:
Cowger W, Gray A, Christiansen SH, De Frond H, Deshpande AD, Hemabessiere L, Lee
E, Mill L, et al. (2020). “Critical Review of Processing and Classification
Techniques for Images and Spectra in Microplastic Research.” *Applied
Spectroscopy*, **74**(9), 989–1010. doi:
[10.1177/0003702820929064](https://doi.org/10.1177/0003702820929064).

Cowger W, Steinmetz Z, Gray A, Munno K, Lynch J, Hapich H, Primpke S,
Expand Down
Loading