Re: [R] Programcode and data in the same textfile

2003-06-12 Thread Greg Louis
On 20030612 (Thu) at 1139:34 -0400, Thomas W Blackwell wrote:

 It also requires knowing how many lines of code precede
 the data lines.  But it _is_ a one-file solution, as
 requested.  Put the following 9 or 10 lines into a
 file named r.source.file, then source it.
 
 data.01 - read.table(file=r.source.file, header=T,
   skip=4, comment.char=)[-1]
 
  # junk Sex  Response
 #   Male 1
 #   Male 2
 #   Female   3
 #   Female   4
 

The nrows parameter can help by letting you put the data early in the
file:

data.01 - read.table(file=r.source.file, header=T,
skip=4, nrows=4, comment.char=)[-1]

#   Sex Response
#   Male1
#   Male2
#   Female  3
#   Female  4

print(data.01)
(more code)

(I got an error line 1 did not have 4 elements when I left the
junk header in place.)

 On Thu, 12 Jun 2003, Ernst Hansen wrote:
 
  PROBLEM: Is there any way I can have a single textfile that contains both
   a) data   b) programcode
  The program should act on the data, if the textfile is source()'ed
  into R.
 
  BOUNDARY CONDITION: I want the data written in the textfile in exactly
  the same format as I would use, if I had data in a separate textfile,
  to be read by read.table().   something like
 
SexRespons
Male   1
Male   2
Female 3
Female 4

Obviously the above doesn't quite meet the requirement, since the data
have to be commented out -- but unless someone implements here
documents, as another list member suggested, I don't think there's a
perfect solution.

-- 
| G r e g  L o u i s  | gpg public key: finger |
|   http://www.bgl.nu/~glouis |   [EMAIL PROTECTED] |
| http://wecanstopspam.org in signatures fights junk email |

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help


Re: [R] executable R scripts

2003-06-09 Thread Greg Louis
On 20030608 (Sun) at 1735:14 -0700, John Zedlewski wrote:
 Hi, I'm a newbie trying to make an R program executable on UNIX, just like one 
 would write an executable perl script by putting #!/usr/bin/perl in the 
 first line, and so on.
 
 It seems, though, that this would only work if I use the BATCH command to 
 tell R to execute the program in its first argument. This would have the 
 unfortunately side-effect of dumping all output to a file rather than stdout.
 
 Additionally, I'd want to see only the results of print statements on 
 stdout, not all off R's output, just as when you source a script with 
 echo=FALSE.

I've seen the other replies, but thought this might be of interest too:
I hacked a hashbang wrapper so you can start an R script with
  #! /bin/sh /usr/bin/setR
and then invoke it with command-line arguments, which get passed to the
script in a character vector called argv.

See http://www.bgl.nu/~glouis/setR.html if you're interested.  I think
the version displayed has a couple of ampersand-lt; that need to be
changed to  if you use 'save as' rather than cutting and pasting.

-- 
| G r e g  L o u i s  | gpg public key: finger |
|   http://www.bgl.nu/~glouis |   [EMAIL PROTECTED] |
| http://wecanstopspam.org in signatures fights junk email |

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help