[R] Problem w/ source

Uwe Ligges ligges at statistik.uni-dortmund.de
Thu Jul 24 17:08:12 CEST 2003


Peter Muhlberger wrote:

> I'm trying to use the source command to run commands from a file.  For
> instance:  source("do.R"), where do.R is a file in the same directory in
> which I am running R.
> 
> The contents of do.R are:
> 
> ls()
> print("hello")
> sum(y1)
> mean(y1)
> 
> 
> After  source("do.R"), all I see is:
> 
> 
>>source("do.R")
> 
> [1] "hello"
> 
> 
> I'm using the X11 version of R for Mac OS X (downloadable binary).  Does
> anyone know how to get source to work?
> 
> Thanks!
> 
> Peter
> 


Works perfectly, but no automatic print() is executed as the default 
when sourcing. When you want the other objects to be printed either use
   print(ls())
   print(sum(y1))
   ...
or use
   source("do.R", print.eval = TRUE)
as described in ?source.

Uwe Ligges




More information about the R-help mailing list