Skip to content
Snippets Groups Projects
Unverified Commit 3a373653 authored by Todor Kondic's avatar Todor Kondic
Browse files

Replace assertthat::asert_that with assert

*R/api.R,R/base.R,R/mix.R <assert>: New function assert. Replaces
 assertthat:assert_that with shiny compatible validation.
parent d1c8e0e8
No related branches found
No related tags found
No related merge requests found
......@@ -97,7 +97,7 @@ mk_comp_tab <- function(m) {
##' @export
read_conf <- function(fn_conf) {
assertthat::assert_that(file.exists(fn_conf),msg=paste("Unable to read the configuration file:", fn_conf))
assert(file.exists(fn_conf),msg=paste("Unable to read the configuration file:", fn_conf))
conf <- yaml::yaml.load_file(fn_conf)
conf <- vrfy_conf(conf)
conf
......@@ -129,26 +129,26 @@ vrfy_conf <- function(conf) {
all_sets<-unique(df_sets$set)
fn_data <- conf$data
assertthat::assert_that(file.exists(fn_data),msg=paste("Data table does not exist:",fn_data))
assert(file.exists(fn_data),msg=paste("Data table does not exist:",fn_data))
mzml <- file2tab(fn_data)
no_files <- which(mzml[,!file.exists(Files)])
no_modes <- which(mzml[,!(mode %in% names(MODEMAP))])
no_sets <- which(mzml[,!(set %in% all_sets)])
assertthat::assert_that(length(no_files)==0,msg = paste("Non-existent data files at rows:",paste(no_files,collapse = ','), "of",fn_data))
assertthat::assert_that(length(no_modes)==0,msg = paste("Unrecognised modes at rows:",paste(no_modes,collapse = ','), "of", fn_data))
assertthat::assert_that(length(no_sets)==0,msg = paste("Unknown sets at rows:",paste(no_sets,collapse = ','),"of", fn_data))
assert(length(no_files)==0,msg = paste("Non-existent data files at rows:",paste(no_files,collapse = ','), "of",fn_data))
assert(length(no_modes)==0,msg = paste("Unrecognised modes at rows:",paste(no_modes,collapse = ','), "of", fn_data))
assert(length(no_sets)==0,msg = paste("Unknown sets at rows:",paste(no_sets,collapse = ','),"of", fn_data))
df_k <- file2tab(fn_cmpd_known)
are_knowns_OK <- shiny::isTruthy(vald_comp_tab(df_k,fn_cmpd_known, checkSMILES=T, checkNames=T))
assertthat::assert_that(are_knowns_OK)
assert(are_knowns_OK,msg='Aborted because known compounds table contained errors.')
## ** Unknowns
if (!is.null(fn_cmpd_unk)) {
df_u <- file2tab(fn_cmpd_unk)
are_unknowns_OK <- shiny::isTruthy(vald_comp_tab(df_u,fn_cmpd_unk, checkSMILES=F, checkMz=T))
assertthat::assert_that(are_unknowns_OK)
assert(are_unknowns_OK, msg='Aborted because unknown compounds table contained errors.')
}
......
......@@ -42,3 +42,5 @@ split_path <- function(path) {
print_table <- function (df) {
paste(apply(df,1,function (row) paste(row,collapse=',')),collapse = "\n")
}
assert <- function(expr,msg) shiny::validate(shiny::need(expr,message=msg))
......@@ -589,7 +589,7 @@ read_setid <- function(fn,known,unk) {
tmp <- setid[,.(ID,set,origin=the_ifelse(ID %in% id_k,"known",NA_character_))]
tmp <- tmp[,.(ID,set,origin=the_ifelse(is.na(origin) & ID %in% id_u,"unknown",origin))]
natmp <- tmp[is.na(origin),.(ID,set)]
assertthat::assert_that(nrow(natmp)==0,msg=paste("The following IDs from set table have not been found in the compound table:","------",print_table(natmp),"------",sep = "\n"))
assert(nrow(natmp)==0,msg=paste("The following IDs from set table have not been found in the compound table:","------",print_table(natmp),"------",sep = "\n"))
tmp
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment