5

Is is somehow possible in R to include a textfile containing R source code and execute at the position where it it is included?

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

I have a file, where I first define functions (~ 200 lines), then I create and set lots of variables by processing lots of files and using the defined functions (~1500 lines) and finally I use the values of the variables for calculations and for plotting (~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 "outsource" the middle Part (Varaible definitions, file reading, general plotting) into a separate file, simply because it is very large and not of interest once I entered all filenames,... . Is here a command like include in R?

0

1 Answer 1

8

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.