[R] R ignoring quantile() in source()d file

Thomas Lumley tlumley at u.washington.edu
Mon Feb 26 04:08:30 CET 2001

On Sun, 25 Feb 2001, Andrew Perrin wrote:

> Can anyone explain this behavior? Essentially, I've created a short file
> to be read in via source() that gets some descriptive information on a
> series of variables in a data frame.  For each variable, I do three
> things:
> print('last.hc.actors')
> quantile(last.hc.actors,probs=seq(0,1,0.1),na.rm=T)
> stem(last.hc.actors)
> where the variable name is (in this case) last.hc.actors.  All that is
> fine, except that R seems to quietly ignore all the quantile() steps.

R is not ignoring quantile(), it simply isn't printing the results,
because you haven't asked it to.

Most R functions do not print their results: that's what print() is for.
They return their results so they can either be printed or used for
further calculations.

 This isn't always obvious to a new user, because if you invoke a function
at the command line the result is print()ed, so

> 1+1
[1] 2
looks just like
> print(1+1)
[1] 2

When source()ing a file, or inside a function, this doesn't happen. You
need to call print() or cat() explicitly to display things on the screen.
In you example you happened to have two other functions, print() and
stem(), that *do* explicitly display their results on the screen.

You probably wanted

print(quantile(last.hc.actors,probs=seq(0,1,0.1),na.rm=T) )

or alternatively, source(,echo=TRUE)


Thomas Lumley			Asst. Professor, Biostatistics
tlumley at u.washington.edu	University of Washington, Seattle

r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch

More information about the R-help mailing list