I am beginner to R. I have written a function: f= function(n=100,p=0.5){ X=rbinom(100,n,p) (mean(X)-n*P)/sqrt(n*p*(1-p)) } But I made a mistake by typing "P" instead of "p". How do I edit this function and improve my mistake. If I use edit(f) it opens an edit window where I am able to change the function but when I type "f" I see the same old function. R does not seem to save my change even though it prompts me to save before I close the edit window. I do not want to retype the whole function all over again. -- View this message in context: http://n4.nabble.com/Editing-a-function-tp1572251p1572251.html Sent from the R help mailing list archive at Nabble.com.
learner1978 <sakp4mcl <at> gmail.com> writes:> > > I am beginner to R. > > I have written a function: > > f= function(n=100,p=0.5){ > X=rbinom(100,n,p) > (mean(X)-n*P)/sqrt(n*p*(1-p)) > } > > But I made a mistake by typing "P" instead of "p". How do I edit this > function and improve my mistake.Two answers: (1) [short term] fix(f) (2) [long term] develop your code in a text editor (Tinn-R, emacs, R source code editor accessible from the menu ...) and cut & paste or source() as necessary.
On Feb 27, 2010, at 11:15 PM, Ben Bolker wrote:> learner1978 <sakp4mcl <at> gmail.com> writes: > >> >> >> I am beginner to R. >> >> I have written a function: >> >> f= function(n=100,p=0.5){ >> X=rbinom(100,n,p) >> (mean(X)-n*P)/sqrt(n*p*(1-p)) >> } >> >> But I made a mistake by typing "P" instead of "p". How do I edit this >> function and improve my mistake. > > Two answers: > > (1) [short term] fix(f) > > (2) [long term] develop your code in a text editor (Tinn-R, emacs, > R source code editor accessible from the menu ...) and cut & paste > or source() as necessary.3) <up-arrow>?>-- David Winsemius, MD Heritage Laboratories West Hartford, CT
Ben Bolker wrote:> > (2) [long term] develop your code in a text editor (Tinn-R, emacs, > R source code editor accessible from the menu ...) and cut & paste > or source() as necessary. >Which I consider the only real solution. From many tutorials, one gets the impression that the purely interactive way is the method of choice, followed by save(). This probably is the reason why it is so difficult to ask for self-contained examples. Maybe we should have some warning displayed in the opening screen: "Are you sure you have a separate editor window open?" Dieter -- View this message in context: http://n4.nabble.com/Editing-a-function-tp1572251p1572557.html Sent from the R help mailing list archive at Nabble.com.