假設你從一個文件名列表開始flist
, 這應該給你一個df如果在一個實驗中錯過了「R」,則execute
列設置爲0
,否則爲1
。例如:
flist <- c("Myexpdate1_R1.txt", "Myexpdate1_R2.txt", "Myexpdate1_R3.txt",
"Myexpdate2_R1.txt", "Myexpdate2_R2.txt")
library(dplyr)
library(stringr)
library(tibble)
flist <- c("Myexpdate1_R1.txt", "Myexpdate1_R2.txt", "Myexpdate1_R3.txt",
"Myexpdate2_R1.txt", "Myexpdate2_R2.txt")
exec <- flist %>%
str_split_fixed("_",2) %>%
as_tibble() %>%
mutate(replicas = str_split_fixed(V2, ".txt",2)[,1]) %>%
group_by(V1) %>%
dplyr::summarise(execute = ifelse (n() == 3, 1, 0))
> exec
# A tibble: 2 × 2
Experiment execute
<chr> <dbl>
1 Myexpdate1 1
2 Myexpdate2 0
然後您可以使用exec
來決定是否運行模擬。例如一個簡單的for
循環:
names(exec)[1] <- "Experiment"
for (exp in seq(along = exec$Experiment)){
if (exec[exp,]$execute == 1){
message("Experiment:", exec[exp,]$Experiment,"--> OK, RUN")
print("DOING SOMETHING")
} else{
message("Experiment:", exec[exp,]$Experiment,"--> FAIL")
print("DOING NOTHING")
}
}
實驗:Myexpdate1 - >確定,RUN
「有所作爲」
實驗:Myexpdate2 - > FAIL
「無爲」
尚不清楚。也許'sapply(split(files,sub(「_。*」,「」,files)),function(x)length(unique(x)))== 3'或者可以是'lapply(split(files,sub (x,read.table,stringsAsFactors = FALSE))' – akrun
你是不是指「如果有一些*(*。*」,「」,files)),函數(x)if(length(unique(x))lapply *文件**存在「,在標題中? – lbusett