[R] Defining and running a simple function

Gabor Grothendieck ggrothendieck at gmail.com
Thu Feb 2 08:17:00 CET 2006


Placing a variable on a line by itself only invokes print if you type
it in from the console.  In a function you must use an explicit
print.

On 2/2/06, Thomas L Jones <DrJones at alum.mit.edu> wrote:
> I am trying, with extremely limited success, to get the R software to
> do some simple computations. Specifically, I defined a test function
> as follows:
>
> fn <- function () {
>
> hw <- "hello world"
>
> hw
>
> s <- seq (0, 0.98, 0.02)
>
> s
>
> }
>
> The output should just be the words "hello world," followed by a
> sequence going from 0 to 0.98.
>
> However, when I call the little test function:
>
> fn ()
>
> the words "hello world" get lost and do not come out. Instead, the
> output begins with
>
> [1] 0.00 0.02, etc
>
> However, when I write a test function for just the words "hello
> world," the words come out just fine.
>
> Here is the setup:
>
> R-2.2.0 using the English language and the console
> Windows XP Home Edition Service Pack 2
> AVG Antivirus Free Version
> Windows built-in firewall
> The R buffered output is disabled.
> Mozilla Firefox 1.5
> Administrator privileges are enabled.
>
> Your advice?
>
> Tom Jones
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>




More information about the R-help mailing list