Note that there are some explanatory texts on larger screens.

plurals
  1. POWhen to use `source()` or `attach()`
    primarykey
    data
    text
    <p>Part of my project directory structure looks like:</p> <pre><code>\projects\project\main.R \projects\project\src </code></pre> <p>where <code>\src</code> contains a bunch of 1-function-per-file, project-specific functions. </p> <p>Q: What's the best practice way to add these functions to the working directory <code>projects\project</code>? </p> <p>There are a few solutions I see:</p> <ol> <li><p><code>attach("./src")</code>. I'm trying to avoid this because (1) the Google Styleguide recommends avoiding the use of <code>attach()</code> and (2) I receive the</p> <pre><code>Warning messages: </code></pre> <p><code>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)</code> when doing this.</p></li> <li><p><code>lapply(paste("./src/",list.files("./src/"),sep=""),source)</code>. This works perfectly fine, it just seems clunky. There has to be a better way, right?</p></li> <li><p>Refer to my functions by their full name <code>./src/myfunc</code>. This will get ugly very quick. I'm sure there's a better way.</p></li> <li><p>Get rid of the <code>./src</code> part 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's <code>ProjectTemplate</code></p></li> <li><p>Throw all the functions in one file, <code>./src/func.R</code> and 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. </p></li> </ol>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload