R. read.table 和 paste() 错误。函数将 FALSE 从 stringsAsFactors = F 粘贴到对象
R. Error with read.table and paste(). Function is sticking FALSE from stringsAsFactors = F to object
我在外置硬盘有一个目录,苹果笔记本:
setwd("/Volumes/HD/1000Genomes/phased_IMPUTE2")
我想 运行 一个包含一些文件的 for 循环:
for(i in 1:22) {
infile1 <-
paste("chr",i,"_cancer.impute.hap",
sep="", stringsAsFactors = F) #
infile2 <-
paste("chr",i,"_cancer.impute.legend",
sep="", header = T, stringsAsFactors = F)
outfile <-
paste("chr",i,"_cancer_phased.txt",sep=" ")
hap <- read.table(infile1)
leg <- read.table(infile2)
# Perform more tasks...
}
但是,我收到以下消息:
Error in file(file, "rt") : cannot open the connection
In addition: Warning message:
In file(file, "rt") :
cannot open file
'chr1_cancer_impute.hapFALSE': No such file or
directory
似乎 paste() 函数正在粘贴 stringsAsFactors = F 的 "FALSE"。我一定是犯了一些非常愚蠢的错误。有人知道这是怎么回事吗?非常感谢
调用 paste
时不需要 stringsAsFactor
选项,因为输出始终是字符。不用它就用 paste
:
paste0("chr", 5, "_cancer.impute.hap")
[1] "chr5_cancer.impute.hap"
据我所知,stringsAsFactor
似乎被忽略了,但 FALSE
值随后被包含在串联中,从而产生了当前输出。
我在外置硬盘有一个目录,苹果笔记本:
setwd("/Volumes/HD/1000Genomes/phased_IMPUTE2")
我想 运行 一个包含一些文件的 for 循环:
for(i in 1:22) {
infile1 <-
paste("chr",i,"_cancer.impute.hap",
sep="", stringsAsFactors = F) #
infile2 <-
paste("chr",i,"_cancer.impute.legend",
sep="", header = T, stringsAsFactors = F)
outfile <-
paste("chr",i,"_cancer_phased.txt",sep=" ")
hap <- read.table(infile1)
leg <- read.table(infile2)
# Perform more tasks...
}
但是,我收到以下消息:
Error in file(file, "rt") : cannot open the connection
In addition: Warning message:
In file(file, "rt") :
cannot open file
'chr1_cancer_impute.hapFALSE': No such file or
directory
似乎 paste() 函数正在粘贴 stringsAsFactors = F 的 "FALSE"。我一定是犯了一些非常愚蠢的错误。有人知道这是怎么回事吗?非常感谢
调用 paste
时不需要 stringsAsFactor
选项,因为输出始终是字符。不用它就用 paste
:
paste0("chr", 5, "_cancer.impute.hap")
[1] "chr5_cancer.impute.hap"
据我所知,stringsAsFactor
似乎被忽略了,但 FALSE
值随后被包含在串联中,从而产生了当前输出。