diff --git a/NAMESPACE b/NAMESPACE index fac9bb5..caa653b 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -2,6 +2,7 @@ export(addAlleles) export(admix1) +export(blanks) export(calculatePopLogml) export(colon) export(computeAllFreqs2) diff --git a/R/blanks.R b/R/blanks.R new file mode 100644 index 0000000..bd1409c --- /dev/null +++ b/R/blanks.R @@ -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="") +} \ No newline at end of file diff --git a/man/blanks.Rd b/man/blanks.Rd new file mode 100644 index 0000000..87471f4 --- /dev/null +++ b/man/blanks.Rd @@ -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 +} diff --git a/tests/testthat/test-convertedBaseFunctions.R b/tests/testthat/test-convertedBaseFunctions.R index ca945c3..66c2ac9 100644 --- a/tests/testthat/test-convertedBaseFunctions.R +++ b/tests/testthat/test-convertedBaseFunctions.R @@ -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), " ") }) \ No newline at end of file