[R] how to organize a lot of R source files

Henrik Bengtsson hb at stat.berkeley.edu
Sat Jan 9 01:56:15 CET 2010


library("R.utils");
sourceDirectory("myRFiles/", modifiedOnly=TRUE);

See ?sourceDirectory (regardless what the Rd help say, any '...'
argument is passed to sourceTo()).

/Henrik

On Fri, Jan 8, 2010 at 7:38 AM, Hao Cen <hcen at andrew.cmu.edu> wrote:
> Hi,
>
> I wonder what is a better way to organize a lot of R source files. I have
> a lot of utility functions written and store them in several source files
> (e.g util1.R, util2.R,..utilN.R). I also have a master file in which the
> source command is used to load all the util.R files. When I need to use
> the utility functions in a new project, I create a new R file (e.g main.R)
> in which I "source" the master file.
>
> The problem with this approach is that anytime a single utility function
> is modified, I need to rerun the source command in main.R to load the
> master file, which loads all the utility R files via a loop over each
> file. Sometimes I have to wait for 10 seconds to get them all loaded.
> Sometimes I forget to run the source command. Is there a way in R to 1)
> only reload the file changed (like a make utility) when I run source on
> all utility files and/or even better 2)  reload the changed utility files,
> when I run a command that use one of those utility functions, without the
> need for me to source those files.
>
> Not sure if packaging solves this issue because the library command has be
> used every time a utility function is modified and in addition the package
> has to be rebuilt. I don't worry about sharing the source files at this
> moment as I am the only user of those utility files.
>
> This may be a common issue many R users face. I wonder how other R users
> solve this issue.
>
> thanks
>
> Jeff
>
> ______________________________________________
> 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.
>



More information about the R-help mailing list