Skip to content

Commit

Permalink
version 0.1.9
Browse files Browse the repository at this point in the history
  • Loading branch information
gastonstat committed Aug 28, 2015
1 parent a5f26e3 commit 863cb58
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 3 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Package: tester
Type: Package
Title: Tests and checks characteristics of R objects
Version: 0.1.8
Date: 2013-11-25
Version: 0.1.9
Date: 2013-12-13
Author: Gaston Sanchez
Maintainer: Gaston Sanchez <gaston.stat@gmail.com>
Description: tester allows you to test characteristics of common R objects.
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export(is_logical_matrix)
export(is_logical_vector)
export(is_lower_triangular)
export(is_matrix)
export(is_multidim)
export(is_multiple)
export(is_natural)
export(is_negative)
Expand Down
46 changes: 46 additions & 0 deletions R/is-one-dim.r
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#'
#' @param x an R object
#' @return whether x is one-dimensional
#' @seealso \code{\link{is_multidim}}
#' @export
#' @examples
#' # vector
Expand Down Expand Up @@ -37,3 +38,48 @@ is_one_dim <- function(x)
# output
one_dim
}


#' @title Test if an object is multi-dimensional
#'
#' @description
#' Returns \code{TRUE} if an object is a matrix or data frame with at
#' least 2 rows and at least 2 columns, \code{FALSE} otherwise
#'
#' @param x an R object
#' @return whether x is multi-dimensional
#' @seealso \code{\link{is_one_dim}}
#' @export
#' @examples
#' # general matrix (nrow>1, ncol>1)
#' is_multidim(matrix(1:9, 3, 3)) # TRUE
#'
#' # general data frame
#' is_multidim(iris) # TRUE
#'
#' # vector
#' is_multidim(1:5) # FALSE
#'
#' # factor
#' is_multidim(iris$Species) # FALSE
#'
#' # one row matrix
#' is_multidim(matrix(1:5, 1, 5)) # FALSE
#'
#' # one column matrix
#' is_multidim(matrix(1:5, 5, 1)) # FALSE
is_multidim <- function(x)
{
multidim = TRUE
if (lacks_dim(x)) {
return(FALSE)
} else {
if (dim(x)[1L] > 1 && dim(x)[2L] > 1) {
multidim = TRUE
} else {
multidim = FALSE
}
}
# output
multidim
}
4 changes: 3 additions & 1 deletion R/is-single.r
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,11 @@ is_single_string <- function(x) {
#' is_single_number("hoskdflksfd") # FALSE
#' is_single_number("1.0") # FALSE
#' is_single_number(1:5) # FALSE
#' is_single_number(NA) # FALSE
#' is_single_number(Inf) # FALSE
is_single_number <- function(x) {
if (is_single(x)) {
is.numeric(x)
(is.numeric(x) && is.finite(x))
} else FALSE
}

Expand Down
40 changes: 40 additions & 0 deletions man/is_multidim.Rd
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
\name{is_multidim}
\alias{is_multidim}
\title{Test if an object is multi-dimensional}
\usage{
is_multidim(x)
}
\arguments{
\item{x}{an R object}
}
\value{
whether x is multi-dimensional
}
\description{
Returns \code{TRUE} if an object is a matrix or data
frame with at least 2 rows and at least 2 columns,
\code{FALSE} otherwise
}
\examples{
# general matrix (nrow>1, ncol>1)
is_multidim(matrix(1:9, 3, 3)) # TRUE

# general data frame
is_multidim(iris) # TRUE

# vector
is_multidim(1:5) # FALSE

# factor
is_multidim(iris$Species) # FALSE

# one row matrix
is_multidim(matrix(1:5, 1, 5)) # FALSE

# one column matrix
is_multidim(matrix(1:5, 5, 1)) # FALSE
}
\seealso{
\code{\link{is_one_dim}}
}

3 changes: 3 additions & 0 deletions man/is_one_dim.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,7 @@ is_one_dim(matrix(1:9, 3, 3)) # FALSE
# general data frame
is_one_dim(iris) # FALSE
}
\seealso{
\code{\link{is_multidim}}
}

0 comments on commit 863cb58

Please sign in to comment.