Open bibsian opened 7 years ago
made the following changes, and checked that results are identical:
# function to subset dataframe by criteria and do error checking
select_by_criteria <- function(x,criteria){
if(!is.null(criteria)) {
# if criteria are specified, subset the dataframe accordingly
out <- subset(x,eval(criteria))
} else {
# if no criteria are specified, do nothing
out <- x
}
# if no results are returned, return an error
if( nrow(out) == 0 ) {
stop( "No matches found. Either:
1. the name of variable(s) you specified is/are incorrect or
2. the values you are looking for are not contained in the variable(s) you specified")
}
return(tbl_df(out))
}
> new <- browse(structure == "size", full_tbl = F)
> identical(old,new)
[1] TRUE
Moved the old function to the UNUSED FUNCTIONS section
suggest closing this issue.
Change the sytanx to make it more apparent that
select_by_criteria()
is just a wrapper forsubset()
that works with lazy eval calls and does error handling.