Skip to content

Commit 7d5b473

Browse files
committed
fixed bug #94
1 parent d07b739 commit 7d5b473

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

R/assertions.R

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,12 @@ assert <- function(data, predicate, ..., success_fun=success_continue,
119119
this.vector <- sub.frame[[column]]
120120
return(apply.predicate.to.vector(this.vector,
121121
predicate))})
122+
# special case for a single row data.frame
123+
if(length(log.mat)==1 && !methods::is(log.mat, "matrix")){
124+
tmp <- names(log.mat)
125+
log.mat <- matrix(dat=log.mat)
126+
colnames(log.mat) <- tmp
127+
}
122128

123129
# if all checks pass in current assertion
124130
if(all(log.mat))
@@ -401,6 +407,13 @@ insist <- function(data, predicate_generator, ...,
401407
return(apply.predicate.to.vector(this.vector,
402408
predicate))})
403409

410+
# special case for a single row data.frame
411+
if(length(log.mat)==1 && !methods::is(log.mat, "matrix")){
412+
tmp <- names(log.mat)
413+
log.mat <- matrix(dat=log.mat)
414+
colnames(log.mat) <- tmp
415+
}
416+
404417
# if all checks pass in current assertion
405418
if(all(log.mat))
406419
return(success_fun(data, "insist", name.of.predicate.generator, colnames(sub.frame), NA, description))

R/utils.R

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,16 +87,16 @@ has_all_names <- function(...){
8787
#'
8888
#' This function checks parent frame environment for a specific set of names; if
8989
#' more columns are present than those specified, an error is raised.
90-
#'
90+
#'
9191
#' This is meant to be used with `assertr`'s `verify` function to check
9292
#' for the existence of specific column names in a `data.frame` that is
9393
#' piped to `verify`. It can also work on a non-`data.frame` list.
94-
#'
94+
#'
9595
#' @inheritParams has_all_names
9696
#' @family Name verification
9797
#' @return TRUE is all names exist, FALSE if not
9898
#' @examples
99-
#'
99+
#'
100100
#' # The last two columns names are switched in order, but all column names are
101101
#' # present, so it passes.
102102
#' verify(
@@ -106,7 +106,7 @@ has_all_names <- function(...){
106106
#' "carb", "gear"
107107
#' ))
108108
#' )
109-
#'
109+
#'
110110
#' # More than one set of character strings can be provided.
111111
#' verify(
112112
#' mtcars,
@@ -115,7 +115,7 @@ has_all_names <- function(...){
115115
#' c("carb", "gear")
116116
#' )
117117
#' )
118-
#'
118+
#'
119119
#' \dontrun{
120120
#' # The some columns are missing, so it fails.
121121
#' verify(mtcars, has_only_names("mpg"))

0 commit comments

Comments
 (0)