Part of my project directory structure looks like:
\projects\project\main.R
\projects\project\src
where \src contains a bunch of 1-function-per-file, project-specific functions.
Q: What’s the best practice way to add these functions to the working directory projects\project?
There are a few solutions I see:
-
attach("./src"). I’m trying to avoid this because (1) the Google Styleguide recommends avoiding the use ofattach()and (2) I receive theWarning messages:1: Reading Unix style database directory (./tmp) from Splus on Windows: may
have problems finding some datasets, especially those whose names
differ only by case (file tmp-script1.ssc should not have been made by
Splus on Windows) in: exists(name, where = db)
when doing this. -
lapply(paste("./src/",list.files("./src/"),sep=""),source). This works perfectly fine, it just seems clunky. There has to be a better way, right? -
Refer to my functions by their full name
./src/myfunc. This will get ugly very quick. I’m sure there’s a better way. -
Get rid of the
./srcpart of my directory and just throw all the functions in the main working directory. The problem with this is that I’d prefer to keep with a directory structure that is close to that of John Myles White’sProjectTemplate -
Throw all the functions in one file,
./src/func.Rand source that. I guess this approach avoids the ugliness of “2.” above, but I’d really like to have one function per file. Just seems cleaner that way.
Try
EDIT
or