Skip to content

Commit

Permalink
Merge pull request #116 from rformassspectrometry/jomain
Browse files Browse the repository at this point in the history
fix: ensure exactmass is numeric
  • Loading branch information
jorainer authored Jul 18, 2024
2 parents 4dadffa + 4bf2940 commit d719ce2
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: CompoundDb
Type: Package
Title: Creating and Using (Chemical) Compound Annotation Databases
Version: 1.9.2
Version: 1.9.3
Authors@R: c(person(given = "Jan", family = "Stanstrup",
email = "[email protected]",
role = c("aut"),
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# CompoundDb version 1.9

## Changes in version 1.9.3

- `compound_tbl_lipidblast`: ensure *exactmass* is of type `numeric`.

## Changes in version 1.9.2

- `compound_tbl_lipidblast`: add parameter `n` to support reading and
Expand Down
4 changes: 2 additions & 2 deletions R/createCompDbPackage.R
Original file line number Diff line number Diff line change
Expand Up @@ -370,10 +370,10 @@ compound_tbl_lipidblast <- function(file, collapse = character(), n = -1L,
nms <- vapply(cmp$names, `[[`, "name", FUN.VALUE = "character")
mass <- unlist(lapply(cmp$metaData, function(z) {
if (z$name == "total exact mass")
z$value
as.numeric(z$value)
}))
if (is.null(mass))
mass <- NA_character_
mass <- NA_real_
frml <- unlist(lapply(cmp$metaData, function(z) {
if (z$name == "molecular formula")
z$value
Expand Down
8 changes: 8 additions & 0 deletions tests/testthat/test_createCompDbPackage.R
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,14 @@ test_that(".import_lipidblast_json_chunk works", {
test_that("compound_tbl_lipidblast works with n > 0", {
f <- system.file("json", "MoNa-LipidBlast_sub.json", package = "CompoundDb")
ref <- compound_tbl_lipidblast(f)
expect_true(is.numeric(ref$exactmass))
expect_true(is.character(ref$compound_id))
expect_true(is.character(ref$name))
expect_true(is.character(ref$inchi))
expect_true(is.character(ref$inchikey))
expect_true(is.character(ref$formula))
expect_true(is.list(ref$synonyms))
res <- compound_tbl_lipidblast(f, n = 4)
expect_true(is.numeric(res$exactmass))
expect_equal(ref, res)
})

0 comments on commit d719ce2

Please sign in to comment.