(How) in R, you can include external source files

Is it possible to include a text file in R containing the source code of R and execute it in the place where it is included?

In PHP, I would use the include command ( http://php.net/manual/en/function.include.php )

I have a file where I first define functions (~ 200 lines), then create and set many variables, process many files and use certain functions (~ 1500 lines), and finally, I use the values ​​of the variables for calculations and for building ( ~ 700 lines).

 # functions readfile <- function (...) { ... } # reading files, general plots,... dataFolder1="..." pdf("param01_Set01.pdf") param01_Set01_SV = readfile(dataFolder1, ...) param01_Set01_KP = readfile(dataFolder1, ...) param01_Set01_NK = readfile(dataFolder1, ...) dev.off() dataFolder2="..." pdf("param01_Set01.pdf") param01_Set02_SV = readfile(dataFolder2, ...) param01_Set02_KP = readfile(dataFolder2, ...) param01_Set02_NK = readfile(dataFolder2, ...) dev.off() ... # dooing specific calculations + plotting result1 = (param01_Set01_SV$xyz + 123) * param02_Set08$xyz plot(...) 

I like to β€œtransfer” the middle part (Varaible definitions, reading files, general drawing) to a separate file, simply because it is very large and not interesting as soon as I entered all the file names .... Is there a command like include in R?

+4
source share
1 answer

the command you are looking for is source() - check ?source for more information. An alternative is sys.source()

+7
source

Source: https://habr.com/ru/post/1389265/


All Articles