我在运用下边readDat函数时总是报错,我试了自己先创建一个temp文件不行,把cmd换成适合windows的系统命令也不行,请各位前辈帮忙找找原因。
f1=readDat("RawData/Study1-Flanker/",22)时
总是报错:Warning: cannot open file 'temp': No such file or directoryError in file(file, "rt") : cannot open the connection
完整的readDat函数是这样的:
readDat=function(fileString,topLen)
{
cmd=paste("ls -1 ",root,fileString, " >temp",sep='')
system(cmd)
filenames=as.vector(read.table('temp'))
dat=NULL
nFiles=dim(filenames)[1]
subLab=sesLab=1:nFiles
for (n in 1:nFiles){
string=filenames[n,1]
sesLab[n]=as.integer(str_sub(string,start = -5, end= -5 ))
subLab[n]=ifelse(str_length(string)==topLen,
as.integer(str_sub(string,start=9,end=10)),
as.integer(str_sub(string,start=9,end=9)))
partial0=read.csv(head=F,
paste(root,fileString,'//',as.character(string),sep=''))
colnames(partial0)=
c('blk','trl','stim','cond','acc','rt')
sub=rep(subLab[n],length(partial0[,1]))
session=rep(sesLab[n],length(partial0[,1]))
partial1=cbind(sub,session,partial0)
dat=rbind(dat,partial1)
}
return(dat)
}