Executing/Loading R Source Files
To execute the commands in an R source file (a .R file) or to load a function defined in a .R file, use ''Source
R code'' from the GUI environment, or source from the command line.
The GUI command is available in the file pull-down menu :
The command line version uses the source command. If myplot.R is in the current directory then executing
> source('myplot.R')
will cause the code in myplot.R to be executed. Or if the
For files that are not located in the current directory, one can specify a full path. For example
> source('Z:/Samples/myplot.R')
or
> source('Z:\\Samples\\myplot.R')
Note that the file separators can forward slashes "/" . If one uses backward slashes "\", they have to be "escaped" by inserting another backward slash.
See also Setting the Current Directory, Editing
R Source Files
Original Documentation : source
Samples
# setting the working directory to Z:\Testing
# and then executing one of the test .R files
setwd('Z:/Testing') source('mytest.R')
UCLA Mathematics Department | ©2000 |