[R] Running code sequentially from separate scripts (but not functions)

rex.dwyer at syngenta.com rex.dwyer at syngenta.com
Thu Feb 24 16:51:50 CET 2011


You don't need to write functions to "source" files:

source("code1.R")
source("code2.R")
source("code3.R")

When you source a file with a bunch of function definitions, the definitions are just assignment statements:

f <- function (x)...
g <- function (x,y,z) ...

Did you think you would break your computer if you just tried this to see if it worked?  :)



-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Dimitri Liakhovitski
Sent: Thursday, February 24, 2011 10:22 AM
To: r-help
Subject: [R] Running code sequentially from separate scripts (but not functions)

Hello!

I am wondering if it's possible to run - in sequence - code that is
stored in several R scripts.
For example:

Script in the file "code1.r" contains the code:
a = 3; b = 5; c = a + b

Script in the file "code2.r" contains the code:
d = 10; e = d - c

Script in the file "code3.r" contains the code:
result=e/a

I understand that I could write those 3 scripts as 3 functions and
source them from another script.
But maybe there is a way of having them run one by one as such?

Thanks a lot!

--
Dimitri Liakhovitski
Ninah Consulting
www.ninah.com

______________________________________________
R-help at r-project.org 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.




message may contain confidential information. If you are not the designated recipient, please notify the sender immediately, and delete the original and any copies. Any use of the message by you is prohibited. 


More information about the R-help mailing list