[R] re ad.table() and setwd() in unix batch mode

Uwe Ligges ligges at statistik.tu-dortmund.de
Fri Jun 19 19:05:51 CEST 2009



tbigdeli wrote:
> My apologies for being overly brief before..
> 
> I submit an R script to batch mode as follows:
> 
> a list of files (object = 'files').  In each iteration, the next file is
> read, alterations made, working directory changed, and output file written
> out.  R will take an inordinate amount of time processing the first file,
> after which no files seem to be read-in.  For batch mode, are my paths
> inappropriate?  Thanks!
> 
> setwd("/home/bigdelitb/chr20/merlin/sim/d5/ped")
> files<-read.table("d5.rf.list",stringsAsFactors=FALSE)
> 
> for(i in 1:length(files$V1)){
> 	setwd("/home/bigdelitb/chr20/merlin/sim/d5/ped")
> 	count <- 1
> 	name<-files$V1[i]
> 	ped <- read.table(name,header=FALSE,stringsAsFactors=FALSE)
>         ...
>         ...
>         setwd("/home/bigdelitb/chr20/merlin/sim/d5/ped/pdt/")
>         write.table(ped,name,quote=FALSE,..)
> }



1. This should do the same for interactive and batch mode given the 
relevant things are not hidden in "...".
2. You are running both inteactive and batch under the same user?
3. Why do you change working directories all the time, you could give 
full path names instead.
4.  1:length(files$V1) is dangerous in loops (if length becomes 0), 
hence use  seq_along(files$V1)

Uwe Ligges





> Uwe Ligges-3 wrote:
>>
>>
>> tbigdeli wrote:
>>> I continually receive the error
>>>
>>> Error in file(file, "r") : cannot open the connection, when running in
>>> batch
>>> mode, but not when inputing directly into R. 
>> Have you given the full path name?
>> If not, do you start both R instances from the same working directory?
>>
>> Otherwise, do you have the same credentials in both cases?
>>
>> Uwe Ligges
>>
>>
>>
>>
>>
>>> Any ideas?
>>>
>>> Thanks!
>>>
>>> TB
>> ______________________________________________
>> R-help at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>>
>




More information about the R-help mailing list