diff --git a/R/colon.R b/R/colon.R new file mode 100644 index 0000000..abe7a12 --- /dev/null +++ b/R/colon.R @@ -0,0 +1,12 @@ +#' @title Vector creation +#' @description Simulates the function `colon()` and its equivalent `:` operator from Matlab, which have a similar but not quite equivalent behavior when compared to `seq()` and `:` in R. +#' @param a initial number +#' @param b final number +#' @export +colon <- function(a, b) { + if (a <= b) { + return(a:b) + } else { + return(vector(mode = "numeric")) + } +} \ No newline at end of file diff --git a/man/colon.Rd b/man/colon.Rd new file mode 100644 index 0000000..4ae3857 --- /dev/null +++ b/man/colon.Rd @@ -0,0 +1,16 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/colon.R +\name{colon} +\alias{colon} +\title{Vector creation} +\usage{ +colon(a, b) +} +\arguments{ +\item{a}{initial number} + +\item{b}{final number} +} +\description{ +Simulates the function `colon()` and its equivalent `:` operator from Matlab, which have a similar but not quite equivalent behavior when compared to `seq()` and `:` in R. +} diff --git a/tests/testthat/test-convertedBaseFunctions.R b/tests/testthat/test-convertedBaseFunctions.R index 3480053..9a9c9c4 100644 --- a/tests/testthat/test-convertedBaseFunctions.R +++ b/tests/testthat/test-convertedBaseFunctions.R @@ -60,4 +60,9 @@ test_that("times works as expected", { object = times(matrix(c(-1.6, 5), 1), c(8, 1)), expected = matrix(c(-12.8, -1.6, 40, 5), 2) ) +}) + +test_that("colon works as expected (hee hee)", { + expect_equal(colon(1, 4), 1:4) + expect_length(colon(4, 1), 0) }) \ No newline at end of file