Skip to content
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
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Package: gDRutils
Type: Package
Title: A package with helper functions for processing drug response data
Version: 1.9.4
Date: 2025-12-02
Version: 1.9.5
Date: 2026-02-12
Authors@R: c(person("Bartosz", "Czech", role=c("aut"),
comment = c(ORCID = "0000-0002-9908-3007")),
person("Arkadiusz", "Gladki", role=c("cre", "aut"), email="gladki.arkadiusz@gmail.com",
Expand Down
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## gDRutils 1.9.5 - 2026-02-12
* `remove_drug_batch` supports atomic vectors as input

## gDRutils 1.9.4 - 2025-12-02
* `convert_se_assay_to_dt` supports merging additional variables

Expand Down
6 changes: 4 additions & 2 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -1003,7 +1003,7 @@ get_env_var <- function(x, ...) {
#' * too long Gnumber
#' * G123456789.1-12
#'
#' @param drug_vec character vector with drug id(s)
#' @param drug_vec atomic vector (e.g., character or integer) with drug id(s)
#' @param drug_p string with regex pattern for drug id. Set to Gnumber format by default: "G\[0-9\]\{8\}".
#' @param sep_p string with regex pattern for separator. Set to any character except for digit and space
#' @param batch_p string with regex pattern for batch substring.
Expand Down Expand Up @@ -1031,11 +1031,13 @@ remove_drug_batch <- function(drug_vec,
drug_p = "^G[0-9]{8}",
sep_p = "[^0-9|^_]",
batch_p = ".+") {
checkmate::assert_character(drug_vec)
checkmate::assert_atomic_vector(drug_vec)
checkmate::assert_string(drug_p)
checkmate::assert_string(sep_p)
checkmate::assert_string(batch_p)

drug_vec <- as.character(drug_vec)

Comment on lines +1039 to +1040
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The sub() function automatically coerces its x argument to a character vector if it's not one already. Therefore, this explicit conversion with as.character() is redundant. You can remove this line and the following empty line for conciseness.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am aware that sub() performs implicit coercion, but I added the explicit as.character() call intentionally to improve workflow transparency. It makes the type conversion explicit for anyone reading the code, ensuring that the expected data format is clear before it hits the regex logic.

p <- paste0("(", drug_p, ")", sep_p, batch_p, "$")
r <- "\\1"
sub(p, r, drug_vec)
Expand Down
2 changes: 1 addition & 1 deletion man/remove_drug_batch.Rd

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

7 changes: 7 additions & 0 deletions tests/testthat/test-utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -764,6 +764,13 @@ test_that("remove_drug_batch works as expected", {
expect_equal(remove_drug_batch("G00001234.28", batch_p = "[0-9]+"),
"G00001234")

# test drug_vec as non-character input
expect_equal(remove_drug_batch(12345L), "12345")
expect_equal(remove_drug_batch(9876.54), "9876.54")
expect_equal(remove_drug_batch(c("G00060245.1", 112233)), c("G00060245", "112233"))
expect_equal(remove_drug_batch(12345.678, drug_p = "[0-9]{5}", sep_p = "\\."), "12345")

# error tests
expect_error(remove_drug_batch(list(drug = "G00000001")), "Assertion on 'drug_vec' failed")
expect_error(remove_drug_batch("G00000001", drug_p = list(1)),
"Assertion on 'drug_p' failed")
Expand Down
Loading