Skip to content

Commit d6df47f

Browse files
committed
added check.number function
1 parent 42428d6 commit d6df47f

4 files changed

Lines changed: 52 additions & 1 deletion

File tree

NAMESPACE

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

33
export(calculate.outputrows)
4+
export(check.number)
45
export(create.sub.objects)
6+
export(create.testing.df)
57
export(datsteps)
68
export(generate.stepsize)
79
export(get.histogramscale)

R/datplot_utility.R

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,5 +195,24 @@ create.sub.objects <- function(DAT_mat, stepsize) {
195195
return(result)
196196
}
197197

198+
#' @title Check for numbers
199+
#'
200+
#' @description Checks if value is either numeric, integer or double and and returns TRUE.
201+
#'
202+
#' @param value A value to check
203+
#'
204+
#' @return TRUE if value is any kind of number, FALSE if value is not
205+
#'
206+
#' @export check.number
198207

199208

209+
check.number <- function(value) {
210+
result <- is.integer(value)
211+
if (result == FALSE) {
212+
result <- is.numeric(value)
213+
if (result == FALSE) {
214+
result <- is.double(value)
215+
}
216+
}
217+
return(result)
218+
}

man/check.number.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-datplot_utility.R

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
source(file = "../create_testing_df.R")
22
library(datplot)
33
library(devtools)
4+
library(testthat)
45

56
testmat <- matrix(c(1,2,3,4,0,0,50,-200,5,-200,50,5), byrow = FALSE, ncol = 3)
67
colnames(testmat) <- c("index", "datmin", "datmax")
@@ -29,8 +30,20 @@ for (r in 1:nrow(testdf)) {
2930
fristlast[r,2] <- seq[length(seq)]
3031
}
3132

32-
library(testthat)
3333
test_that("sequence returns first and last values", {
3434
expect_equal(fristlast[,1], testdf[,3])
3535
expect_equal(fristlast[,2], testdf[,4])
3636
})
37+
38+
39+
test_that("check.number returns true for numbers false for other", {
40+
expect_true(check.number(numeric(1)))
41+
expect_true(check.number(double(1)))
42+
expect_true(check.number(integer(1)))
43+
expect_false(check.number(character(1)))
44+
expect_false(check.number(factor(1)))
45+
})
46+
47+
48+
49+

0 commit comments

Comments
 (0)