Skip to content
Snippets Groups Projects
Commit 2eb43aed authored by Todor Kondić's avatar Todor Kondić
Browse files

Sets are read from compound lists, or created based on the file name.

parent d11926e7
No related branches found
No related tags found
No related merge requests found
......@@ -127,10 +127,12 @@ load_compound_input <- function(m) {
# nonexist <- setdiff(fnfields,fields)
coll[[l]] <- dt #if (length(nonexist)==0) dt else dt[,(nonexist) := NULL]
coll[[l]]$ORIG <- fn
}
cmpds <- if (length(fns)>0) rbindlist(l=c(list(EMPTY_CMPD_LIST), coll), use.names = T, fill = T) else EMPTY_CMPD_LIST
## Process sets.
cmpds = process_cmpd_sets(cmpds)
dups <- duplicated(cmpds$ID)
dups <- dups | duplicated(cmpds$ID,fromLast = T)
dupIDs <- cmpds$ID[dups]
......
......@@ -143,3 +143,14 @@ uniqy_slugs <- function(slugs) {
dt = data.table::data.table(slug=slugs)
dt[,slug:=fifelse(rep(.N==1L,.N),slug,paste0(slug,"_",seq(1L,.N))),by="slug"]$slug
}
process_cmpd_sets <- function(cmpdlist) {
## Process sets.
if (! ("set" %in% colnames(cmpdlist))) cmpdlist$set=NA_character_ else cmpdlist[,set:=as.character(set)]
## Extract set names and fill out the empty ones.
slugs = cmpdlist[,.(slug=fifelse(is.na(set),gen_fname_slug(ORIG),set)),by=ORIG]
slugs[,slug:=uniqy_slugs(slug)]
cmpdlist[slugs,set:=i.slug,on="ORIG"]
cmpdlist
}
# process_cmpd_sets
Code
x
Output
ID ORIG set
1: 1 f1.csv f1_2
2: 2 f1.csv f1_2
3: 3 f2.csv aks
4: 4 f3.csv se32
5: 5 f3.csv se32
---
Code
x
Output
ID ORIG set
1: 1 b/f2.csv f2
2: 2 a/f1.csv f1
3: 3 q/f/g/f2.csv aks
4: 4 d/e/f/f3.csv se31
5: 5 m/n/q/f3.csv se32
......@@ -16,3 +16,17 @@ test_that("uniqy_slugs",{
message(paste(out,coll=','))
expect_true(1==1)
})
test_that("process_cmpd_sets",{
## Test case when no base filename is the same.
cmpdl = data.table(ID=1:5,ORIG=c("f1.csv","f1.csv","f2.csv","f3.csv","f3.csv"),set=c(NA_character_,NA_character_,"aks","se31","se32"))
x = process_cmpd_sets(cmpdl)
expect_snapshot(x)
## Test case with similar base filenames.
cmpdl = data.table(ID=1:5,ORIG=c("b/f2.csv","a/f1.csv","q/f/g/f2.csv","d/e/f/f3.csv","m/n/q/f3.csv"),set=c(NA_character_,NA_character_,"aks","se31","se32"))
x = process_cmpd_sets(cmpdl)
expect_snapshot(x)
})
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