I am writing more than 6 functions and save them in my R.project. Every time, to start working using my project, I need to run each function manually one by one. Is there a way that I can load all these functions automatically?
Asked
Active
Viewed 2,634 times
1
-
2Create a package and then you need to load only the package – akrun Mar 20 '18 at 08:14
-
@akrun can I extend my project automatically to a package. – Mar 20 '18 at 08:15
-
Thank you @akrun so much for your comment. – Mar 20 '18 at 08:17
4 Answers
6
You have two options:
Create your own package and load it on the start-up, you will have all the function available. A tutorial
Customize R start-up loading automatically your R files containing your functions. A tutorial and an example

Terru_theTerror
- 4,918
- 2
- 20
- 39
0
If you don't wish to take the package approach (which I agree is the best approach), you could stack all your functions on top of one another in an R script and source it on startup. One step instead of 6. End up with all the functions in your .GlobalEnv
Put this in an R script:
###Put in a script
eeee <- function(){
cat("yay I'm a function")
}
ffff <- function(){
cat("Aaaaaah a talking function")
}
If you use RStudio, the code would be as below. Otherwise change the source location. Do this in console (or in a script):
###Do this
source('~/.active-rstudio-document')
Then you can do:
eeee()
yay I'm a function
ffff()
Aaaaaah a talking function

Neal Barsch
- 2,810
- 2
- 13
- 39
0
You can run the below script before starting your work:
source_code_dir <- "./R/" #The directory where all source code files are saved.
file_path_vec <- list.files(source_code_dir, full.names = T)
for(f_path in file_path_vec){source(f_path)}

mishraP
- 209
- 2
- 7