Skip to content

Commit 68480dc

Browse files
committed
add and export function has_star
1 parent 51e2e6f commit 68480dc

4 files changed

Lines changed: 39 additions & 0 deletions

File tree

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Generated by roxygen2: do not edit by hand
22

33
export(format_wells)
4+
export(has_star)
45
export(kvlist_to_table)
56
export(long_to_shortnames)
67
export(read_data)

R/utils.R

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,14 @@ kvlist_to_table <- function(kvlist, guide, reverse.translate = TRUE) {
4646
star_to_number <- function(x) {
4747
as.numeric(stringr::str_remove_all(x, "[*x?]"))
4848
}
49+
50+
#' Check if a string has a star
51+
#' @param x A character vector
52+
#' @return A logical vector
53+
#' @description
54+
#' This function checks if a string has a star, x or a question mark.
55+
#' @export
56+
#'
57+
has_star <- function(x) {
58+
stringr::str_detect(x, "[*x?]")
59+
}

man/has_star.Rd

Lines changed: 17 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/test-utils.R

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,16 @@ test_that("function star_to_number works", {
1717
expect_equal(star_to_number("0*"), 0)
1818
expect_equal(star_to_number("1.15*"), 1.15)
1919
expect_equal(star_to_number(c("1.15","0*")), c(1.15, 0))
20+
expect_equal(star_to_number(c("*1.15","*0")), c(1.15, 0))
21+
})
22+
23+
test_that("function has_star works", {
24+
expect_equal(has_star(NA), NA)
25+
expect_equal(has_star("1*"), TRUE)
26+
expect_equal(has_star("10*"), TRUE)
27+
expect_equal(has_star("0*"), TRUE)
28+
expect_equal(has_star("1.15*"), TRUE)
29+
expect_equal(has_star(c("1.15","0*")), c(FALSE, TRUE))
2030
})
2131

2232
test_that("function kvlist_to_table works", {

0 commit comments

Comments
 (0)