[R] Dealing with missing EOL at end of file

Duncan Murdoch murdoch at stats.uwo.ca
Wed Sep 17 17:30:59 CEST 2008


On 9/17/2008 9:03 AM, Dennis Fisher wrote:
> Colleagues,
> 
> I am using R 2.7.2 on all three platforms (OS X; Windows; Linux) and I  
> have encountered the following problem:
> 
> I use R to issue a system call the execute a command in the OS.  For  
> example:
> 
> system("DOSOMETHING TOSOMEFILE")
> 
> In most situations, this task completes successfully and control  
> returns to R.  However, in rare situations, the target file  
> (TOSOMEFILE) is missing an EOL character in its final line.  In that  
> situation, the task DOSOMETHING hangs and control never returns to R.   
> Exiting R requires that I kill the process.
> 
> I believe that a solution would be to add an EOL character to the  
> final line of the target file before executing DOSOMETHING.  I presume  
> that this could be done by reading TOSOMEFILE with readLines,  
> appending an EOL character, writing to disk, then executing TOSOMEFILE  
> on the revised target.

No need to append the EOL, writeLines will automatically terminate each 
line.  readLines will by default give a warning if there wasn't one present.

> 
> Questions:
> 
> 1.  Is there are easier approach to the entire problem?
> 
> 2.  Is there any risk in having two EOL characters at the end of the  
> file (i.e., need I test for the presence of EOL at the end of the file  
> or can I append EOL to any file with no potential harm?

That really depends on what DOSOMETHING does.  Does it care if there's 
an extra blank line at the end?  Can you tell it to ignore the lack of one?

Duncan Murdoch


> 
> Dennis
> 
> 
> Dennis Fisher MD
> P < (The "P Less Than" Company)
> Phone: 1-866-PLessThan (1-866-753-7784)
> Fax: 1-415-564-2220
> www.PLessThan.com
> 
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> 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