Added nargin function

This commit is contained in:
Waldir Leoncio 2020-10-19 09:49:30 +02:00
parent 03089d7e42
commit 3250349c60
3 changed files with 43 additions and 5 deletions

View file

@ -201,4 +201,20 @@ test_that("isspace works as expected", {
X <- '\t a b\tcde f'
expect_identical(isspace(chr), c(0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0))
expect_identical(isspace(X), c(1, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0))
})
test_that("nargin works correctly", {
addme <- function(a, b) {
if (nargin() == 2) {
c <- a + b
} else if (nargin() == 1) {
c <- a + a
} else {
c <- 0
}
return(c)
}
expect_equal(addme(13, 42), 55)
expect_equal(addme(13), 26)
expect_equal(addme(), 0)
})