我正在嘗試使用以下代碼將一些檔案從一個位置移動到另一個位置:
#exclude files with name .maf
filez <- grep(list.files(path="."), pattern='.maf', invert=TRUE, value=TRUE)
filez <- data.frame(filez)
#select files with sepcial chr at 14 & 15 position in file name
Tumor <- filez %>% filter(between(as.integer(substr(filez, 14, 15)), 01, 09))
dir.create("Tumor")
file.move(Tumor$filez, "Tumor")
但是我收到錯誤
file.move(Tumor$filez, "Tumor")
Error in argchk_move_files(files = files, destinations = destinations, :
Assertion on 'files' failed: Must be of type 'character', not 'factor'.
我不知道為什么會出現錯誤。
uj5u.com熱心網友回復:
我在檔案夾中設定了一些檔案來說明:
> list.files(".")
[1] "abc01.maf" "abc02.maf" "abc03.maf" "abc04.maf" "abc05.maf" "abc06.maf"
[7] "abc07.maf"
將一些檔案放入一個向量中(這對你來說有點不同,因為我認為你得到的所有檔案都不.maf是,但這已經足夠接近了):
> filez <- grep(list.files(path="."), pattern='.maf', value=TRUE)
> filez
[1] "abc01.maf" "abc02.maf" "abc03.maf" "abc04.maf" "abc05.maf" "abc06.maf"
[7] "abc07.maf"
現在使用從位置 4 和 5 的數值在 3 和 6 之間派生的條件對該向量進行子集:
> filez[dplyr::between(as.integer(substr(filez, 4,5)), 3, 6)]
[1] "abc03.maf" "abc04.maf" "abc05.maf" "abc06.maf"
完畢。無需創建資料框或使用filter.
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/433104.html
