I have a standard data analysis procedure that I need to run on various (~50 datasets). I have been developing it for some time and now I got to the point where I would like to turn it into a function which takes a dataset and spits out some sensible table for each dataset. However, the procedure as done spans over four script files and so far I have used source
from one to another to run it, but it seems it seems to be impossible with function
.
I have a following problem:
foo <- function(data) {
a <- somevariable
source("..somefile..") #The code in there uses a, but a is not in the workspace...
..
continue
..
}
The code crashes when you run it on a dataset.
Is there some way (command) that would just copy-paste the commands from other files while compiling (don't know how I could call it differently, even though it is not real compiling) the function? I know I can just copy-paste it myself, but I would rather not, because various steps include neural-networks and ARFIMA estimations which I would like to keep in separate files for the sake of readability of the code. Anyway the function would after copy-paste be something like 200 lines of code, which is definitely not user friendly...
Thx