Hello, 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. Further, I wonder if there is any way to do some output for control within the function (or any other possibilities to debug in a way). Maybe, I have chosen a completely wrong way? I only want to make it easy to create some graphical visualizations of data which will be read in by csv. files, has to be converted and then displayed depending on some "displaying parameters". Ciao, Antje
Hello Am Donnerstag, 3. August 2006 09.36 schrieb Antje:> Hello, > > 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. > Further, I wonder if there is any way to do some output for control > within the function (or any other possibilities to debug in a way).source("your-r-file.R") mybmi <- bmi(180, 70)> Maybe, I have chosen a completely wrong way? I only want to make it easy > to create some graphical visualizations of data which will be read in by > csv. files, has to be converted and then displayed depending on some > "displaying parameters".look here (directory R): http://tomix.homelinux.org/~thomas/eth/5_semester/semesterarbeit_WS_2005_2006/ auswertung.R is the main file.> Ciao, > Antje > > ______________________________________________ > 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 and provide commented, minimal, > self-contained, reproducible code.
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?)