Skip to content

r function definition

4 messages · qq, Jeff Newmiller, Robert Baer +1 more

qq
#
I am a very new R user. I am trying to write functons and debug functions.
One problem for me is that I need to alwasy copy the whole function body and
resubmit to R console every time I changed even one line of the function.
Because I have long algorithm function, copying and pasting is very tedious
for me. I assume if I save the function files, R should be able to just use
the new function body since it is a scripting language. Can somebody let me
know his best practice of using R function?



--
View this message in context: http://r.789695.n4.nabble.com/r-function-definition-tp4651943.html
Sent from the R help mailing list archive at Nabble.com.
#
?source
---------------------------------------------------------------------------
Jeff Newmiller                        The     .....       .....  Go Live...
DCN:<jdnewmil at dcn.davis.ca.us>        Basics: ##.#.       ##.#.  Live Go...
                                      Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/Batteries            O.O#.       #.O#.  with
/Software/Embedded Controllers)               .OO#.       .OO#.  rocks...1k
--------------------------------------------------------------------------- 
Sent from my phone. Please excuse my brevity.
qq <qiz5 at hotmail.com> wrote:

            
#
On 12/3/2012 2:30 PM, qq wrote:
You might be at the point where a development environment is useful.  
There are multiple choices, but I'm quite fond of RStudio.
http://www.rstudio.com/ide/download/

Rob

  
    
#
Are you using windows? If you are you may want to try to run your R code from a batch file:
REM on Microsoft Windows (adjust the path to R.exe as needed) 
"C:\Program Files\R\R-2.13.2\bin\x64\R.exe" CMD BATCH    "C:\Users\Frank\Documents\R\Projects\Heinrich\Heinrich.txt" "C:\Users\Frank\Documents\R\Projects\Heinrich\Heinrich.out"
PAUSE

Where ...Heinrich.txt is the following R code in a text file:
pdf("Heinrich.pdf")
## load Pearson package
library(PearsonDS)
## calculate probability density function Fig. 1
x <- seq(0.0, +20.0, length=100)
hx<- dpearsonIV(x,m=2.25,nu=5,location=17,scale=2)
k<-0.0206631
plot(x, hx , type="l", lwd=2, tck=1, xlab="x value",  ylab="Density", main="J. Heinrich Fig. 1")
## calculate probability density function Fig 2
hx<- dpearsonIV(x,m=0.75,nu=1.0,location=15,scale=0.5)
k<-0.218991
plot(x, hx , type="l", lwd=2, tck=1, xlab="x value",  ylab="Density", main="J. Heinrich Fig. 2")
quit()
and Heinrich.out will contain the output of the results of the commands. Look at Heinrich.out for results and errors. Then correct the text file and rerun.
GL
Frank
Chicago
----------------------------------------