Translated basic Matlab function blanks()

This commit is contained in:
Waldir Leoncio 2020-07-13 13:59:35 +02:00
parent 5fdff9fee2
commit 32e5020d62
4 changed files with 46 additions and 0 deletions

View file

@ -2,6 +2,7 @@
export(addAlleles)
export(admix1)
export(blanks)
export(calculatePopLogml)
export(colon)
export(computeAllFreqs2)

14
R/blanks.R Normal file
View file

@ -0,0 +1,14 @@
#' @title Blanks
#' @description Create character vector of blanks
#' @details This function emulates the behavior of a homonimous function from Matlab
#' @param n length of vector
#' @return Vector of n blanks
#' @author Waldir Leoncio
#' @export
blanks <- function(n) {
if (n < 0) {
warning("Negative n passed. Treating as n = 0")
n <- 0
}
paste(rep(" ", n), collapse="")
}

23
man/blanks.Rd Normal file
View file

@ -0,0 +1,23 @@
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/blanks.R
\name{blanks}
\alias{blanks}
\title{Blanks}
\usage{
blanks(n)
}
\arguments{
\item{n}{length of vector}
}
\value{
Vector of n blanks
}
\description{
Create character vector of blanks
}
\details{
This function emulates the behavior of a homonimous function from Matlab
}
\author{
Waldir Leoncio
}

View file

@ -168,4 +168,12 @@ test_that("cell works as expected", {
expect_equal(cell(2), array(dim = c(2, 2)))
expect_equal(cell(3, 4), array(dim = c(3, 4)))
expect_equal(cell(5, 7, 6), array(dim = c(5, 7, 6)))
})
test_that("blanks works as expected", {
expect_warning(blanks(-1))
expect_equal(suppressWarnings(blanks(-1)), "")
expect_equal(blanks(0), "")
expect_equal(blanks(1), " ")
expect_equal(blanks(10), " ")
})