r function definition

classic Classic list List threaded Threaded
4 messages Options
qq
Reply | Threaded
Open this post in threaded view
|

r function definition

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?
Reply | Threaded
Open this post in threaded view
|

Re: r function definition

Jeff Newmiller
?source
---------------------------------------------------------------------------
Jeff Newmiller                        The     .....       .....  Go Live...
DCN:<[hidden email]>        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 <[hidden email]> wrote:

>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.
>
>______________________________________________
>[hidden email] 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.

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: r function definition

Robert Baer
In reply to this post by qq
On 12/3/2012 2:30 PM, qq wrote:
> 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?
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

>
>
> --
> 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.
>
> ______________________________________________
> [hidden email] 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.


--
__________________
Robert W. Baer, Ph.D.
Professor of Physiology
Kirksille College of Osteopathic Medicine
A. T. Still University of Health Sciences
Kirksville, MO 63501 USA

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: r function definition

FJ M
In reply to this post by qq

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
----------------------------------------

> Date: Mon, 3 Dec 2012 12:30:31 -0800
> From: [hidden email]
> To: [hidden email]
> Subject: [R] r function definition
>
> 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.
>
> ______________________________________________
> [hidden email] 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.    
______________________________________________
[hidden email] 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.