Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to do R includes [duplicate]

Tags:

r

Possible Duplicate:
Include files R?

I cannot find useful documentation about an R file including another R file. R is a very short word is ignored by search engines.

I have file.R and include.R and I want to do something like this:

// in include.R I want to load libraries
library(phpSerialize)

// in file.R include the previous file and use directly the given library
include(include.R)

x = rnorm(10)
y =  phpSerialize(x)
like image 284
Elzo Valugi Avatar asked Dec 02 '10 10:12

Elzo Valugi


2 Answers

Maybe you are just looking for source(file="include.R"). Note that source() executes the commands in the specified file, it does not (like PHP include) simply paste the contents of that file into the including file. Which is probably not important in your case.

like image 186
caracal Avatar answered Sep 19 '22 15:09

caracal


In addition to source, you may be interested in sys.source. It gives you more control over the environment the file is evaluated in.

like image 34
Joshua Ulrich Avatar answered Sep 19 '22 15:09

Joshua Ulrich