[R] Using R to create pdf's from each file in a directory

gecko951 ben.lairson at gmail.com
Wed Apr 25 03:34:06 CEST 2007


Did some reading and tried the following to exclude certain data columns but
my syntax must be slightly off...

> workdir <- '/tmp/data'
> for (x in dir(workdir,pattern='.csv$')){
+    d <- read.table(paste(workdir,'/',x,sep=''), sep=",", header=TRUE,
colClasses=list(#, BlockType, ThreadName, BytesSoFar, BlockSize,
BlockOffset, BlockStart, BlockEnd, Duration, BytesPerSecond, MBBlockSize,
Path=NULL))
+    pdf(paste(workdir,'/',sub('.csv$','.pdf',x),sep=''))
+    plot(d$BlockSeqNum, d$MBs,
Error: syntax error in:
"   pdf(paste(workdir,'/',sub('.csv$','.pdf',x),sep=''))
   plot"
Execution halted




gecko951 wrote:
> 
> Jeff's code works beautifully with a couple changes to my dataset. I must
> change my data column MB/s to MBs.  R seems to think that the "s" is
> another column if I try to use MB/s.  Is there a way that I can make R
> allow special characters in the column names?
> 
> The second step to getting this to work was to remove the dozen or so
> additional columns that are part of my csv but have no relevance to the
> graph. Does R want me to pass code telling it to filter out unneeded
> columns?
> 
> Regards,
> 
> Ben
> 
> 
> Patrick Connolly-2 wrote:
>> 
>> On Fri, 20-Apr-2007 at 11:10PM -0500, Jeffrey Horner wrote:
>> 
>> 
>> |> workdir <- '/tmp/data'
>> |> for (x in dir(workdir,pattern='.csv$')){
>> |>    d <- read.table(paste(workdir,'/',x,sep=''), sep="\t", header=TRUE)
>> 
>> If they're CSV files, I don't think sep = "\t" will be correct. Try ","
>> 
>> best
>> 
>> -- 
>> ~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.   
>>    ___    Patrick Connolly   
>>  {~._.~}          		 Great minds discuss ideas    
>>  _( Y )_  	  	        Middle minds discuss events 
>> (:_~*~_:) 	       		 Small minds discuss people  
>>  (_)-(_)  	                           ..... Anon
>> 	  
>> ~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.
>> 
>> ______________________________________________
>> R-help at stat.math.ethz.ch 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.
>> 
>> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Using-R-to-create-pdf%27s-from-each-file-in-a-directory-tf3621434.html#a10172857
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list