This Stack-Overflow thread made me realize that I can reuse my custom functions.
Like that OP, I have some custom written functions which I use on regular basis. I am feeling a bit tired copying the code and pasting it on editor every-time I want to use it. I didn't follow the answers completely...
Consider the following simple example.
1. Can I save the code somewhere and read it from there and use it without having to paste the code on the editor?
[I know the answer is Yes].
2. What format do it save the script as? .txt or as .RFile and where? Can I create a working directory and put my script there and load it every-time I want to use?
3. How do I load it into Editor. Using source function?
Thanks for your help.
Like that OP, I have some custom written functions which I use on regular basis. I am feeling a bit tired copying the code and pasting it on editor every-time I want to use it. I didn't follow the answers completely...
Consider the following simple example.
Code:
## Custom function to work out exponential probability
foo<- function(x,k){
if(x<0){
out<-"Not Allowed: Illegal x ranges"
} else {
out<-k*exp(-k*x)
}
return(out)
}
[I know the answer is Yes].
2. What format do it save the script as? .txt or as .RFile and where? Can I create a working directory and put my script there and load it every-time I want to use?
3. How do I load it into Editor. Using source function?
Code:
setwd("C:/test") ## directory where code is
## Supose I call my code file exponential.
source("C:/test/exponential.RFile") ## this doesn't work...