[R] FORMAT EDITING

MacQueen, Don macqueen1 at llnl.gov
Mon Feb 11 22:42:00 CET 2013


You say, "Š use the R output file in Fortran Š "
I guess that means that R is writing an output file which will then be
used as an input file for a fortran program.

In that case, you need to go back to how R is writing the output file,
find out why it is writing blank lines, and correct it. As far as leading
spaces and other formatting aspects, you can create any output format you
want using functions like cat(), formatC(), sprintf() and others.

Otherwise, if what you want R to do is read the input file, remove the
empty lines, and write a new output file, this seems to do it (on my
system):

  tmp <- scan('des.txt', what='', sep='\n')
  cat( paste(tmp,collapse='\n') , file='des.new')

Because as far as I can tell from your attached text file, the input and
output are identical except for the blank lines.


You might also be dealing with issues of different operating systems
having different conventions for new lines (DOS vs unix, etc). emacs tells
me you input data is DOS, meaning new lines are indicated (if I remember
correctly) by a sequence of two characters, "carriage return" followed by
"line feed", but the fortran code may be expecting a single character.

-Don

-- 
Don MacQueen

Lawrence Livermore National Laboratory
7000 East Ave., L-627
Livermore, CA 94550
925-423-1062





On 2/11/13 8:41 AM, "eliza botto" <eliza_botto at hotmail.com> wrote:

>
>
>Dear R users,[IF THE FORMAT OF MY EMAIL IS NOT CLEAR, I HAVE ATTACHED A
>TEXT FILE FOR A CLEAR VIEW]
>I would like to use the R output file in Fortran. my file Is exactly in
>the following format.
> ELISA/BOTTO  wATER INN
> FROM 1900 11 1 TO 1996 12 31
> 1901.11. 1 447.000
> 1901.11. 2 445.000
> 1901.11. 3 445.000
> 1924.11. 4 445.000
> 1924.11. 5 449.000
> 1924.11. 6 442.000
> 1924.11. 7 445.000
>so you can see that there is a single space, in between these lines and
>also a single space from left margin. i would like to
>keep the left margin space, but really like to eliminate the space
>between the lines so that i get an output text file which
>could look like
> ELISA/BOTTO  wATER INN               FROM 1900 11 1 TO 1996 12 31
>1901.11. 1 447.000 1901.11. 2 445.000 1901.11. 3 445.000 1924.11. 4
>445.000 1924.11. 5 449.000 1924.11. 6 442.000 1924.11. 7 445.000
>As i am working in fortran i would really like to keep the said
>format.THANKS IN ADVANCE
>ELISA 		 	   		  



More information about the R-help mailing list