Tuesday, 15 June 2010

Including a function within an R script -


I hope there is a script that I can paste in R at the same time. Ideally this script has lines of code with different functions. But as of now, I have to paste the bits of my code in a one-time-one, because (as I've written) the function will not work when it runs at the same time with the code given below Will go

For the code given below, I have to keep the user input initial data, and then run the calculation on it. Since I can not run many "redline" calls in one line, so I wrapped them in a function called Define. But the following code will not work if I paste it in R at a time.

  define & lt; -function () {N & lt; -readline ("EnterDeployment #") Y & lt; -a.numeric (name ("list" = y, "name" = n, "length" = "," "line" l))} def <-Define () name & lt; -Def $ name Year & lt; -Def $ Years L & lt; -Def $ Length Readline (Paste ("UPDN =", name, "year =", year, "distance =", l, "If this is a correct press return") SP = "")) D & lt; -L / 4F & lt; -D * 5   

But if I break it into segments, it works just fine. Is there any way to include one or more functions in a row?

I have no reason The function does not even have other steps, it will solve the problem and it will be due to the formation of the IMHO.

  FOO & lt; - function () {define & lt; -function () {N & lt; -readline ("EnterDeployment #") Y & lt; -s numeric ("(Which year was deployment?")) L.L.L.; -A.Nemmic (readline ("What is the distance?" ) The name ("year" = y, "name" = n, "length" = l)} def <-Define () name & lt; -Def $ name year & lt; -Def $ years l & lt ; -Def $ length line (line paste ("UPDN =", name, "year =", year, "d Pre = ", l," if this is the correct press returns ", SP =" ")) D & lt; -L / 4F & LT; -D * 5 list (D = D, F = F)}   

We have access to:

  & gt; FOO () EnterDeployment # 12 What was the deployment? 2012 What is the distance? 54 UPDN = 12 years = 2012 distance = 54 If this is correct press return $ D [1] 13.5 $ F [1] 67.5   

Of course, you will need a source < / Code> . is in the file FOO () , but this is not a problem.

Why is this better? It is okay to organize all the steps involved in any such ceremony. You also do not pollute things made as intermediate steps. Finally, if other users have to pass it, you can package it as R package (you do not have to type the document - just add a bare bones .rd file).

No comments:

Post a Comment