Re: [R] run self written functions

From: Dieter Menne <>
Date: Fri 04 Aug 2006 - 00:57:19 EST

Antje <niederlein-rstat <at>> writes:

> I'm not sure if I'm in the right place with my question...
> I'm running R on Windows and wrote a function and saved it as .R file.
> It looks like this:
> bmi <- function(weight, height) {
> bmi <- weight / height^2
> bmi
> }
> If I want to use this function, I have to mark everything and then press
> Ctrl-R. But then everything single line is executed on the command line,
> which means that I will "loose" my history when the code becomes longer.

I suggest that you forget the "history" function, it tends to accumulate all the nonsense we make. Use the following method instead: Keep a RGui (assuming Windows) on the left half of your screen, and an editor (Tinn-R, I suggest, if you are no emacian) on the right half. Write everything you plan to keep in the editor, and send it to RGui using the menu items of the editor provided. That way, you end up with a nice little program that you can take home and re-run tomorry, when your BMI has changed (I hope it stays constant).

R is a bit different from other programming languages, it does not need the assignment to the function name. The following is the same as your function.

bmi <- function(weight, height) weight / height^2

(TÜ) mailing list PLEASE do read the posting guide and provide commented, minimal, self-contained, reproducible code. Received on Fri Aug 04 01:45:08 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Fri 04 Aug 2006 - 02:20:21 EST.

Mailing list information is available at Please read the posting guide before posting to the list.