[R] run self written functions
Dieter Menne
dieter.menne at menne-biomed.de
Thu Aug 3 16:57:19 CEST 2006
Antje <niederlein-rstat <at> yahoo.de> 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
Dieter
(TÜ)
More information about the R-help
mailing list