Added basic colon function
This commit is contained in:
parent
f8f65f176c
commit
1b79529e4b
3 changed files with 33 additions and 0 deletions
12
R/colon.R
Normal file
12
R/colon.R
Normal file
|
|
@ -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"))
|
||||
}
|
||||
}
|
||||
16
man/colon.Rd
Normal file
16
man/colon.Rd
Normal file
|
|
@ -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.
|
||||
}
|
||||
|
|
@ -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)
|
||||
})
|
||||
Loading…
Add table
Reference in a new issue