Organizing a project
1. Organizing a project
The end is in sight! In these last two videos, we'll think about ways of structuring all of our analyses.2. It starts with something small
I don't know about you, but all my R projects start with 1 line that becomes 10. Import one little package suddenly becomes five. And a single file results in a mess.3. Project Set-up
They is a way to avoid this chaos! Every project I now work on has it's own directory with it's own name. For example, this course has it's own directory called defensive r programming.# If I'm working on a survival project, I might use the word survival. The directory name gives the project context.4. Directory: input/
Inside this directory, I always use the same structure. I always have a directory called input that contains data files. Usually CSV and excel files. But no R code. In my case, this is usually data sent to me from a collaborator. I go to great lengths to only edit these files in R. This creates a reproducible pipeline.5. Directory: R/
I always have a directory call R. This contains R code. Notice, it's not called R_analysis, or R_code or R_survival. Just plain R.6. Directory: R/
In this directory, I always have a file called __load.R__ that loads data from `input/` This means I can give you any project I'm working on and you can easily load the data and not have to think where the data is located.7. The load.R file
In the load dot R file, all paths are relative. I haven't hard coded in my username or directory structure. My code is portable.8. Other R files
Of course I have other R files. But they all follow the same concept. Simple, descriptive names. - `clean.R` for cleaning your data - `function.R` - any helper functions - `analysis.R` - the actual analysis I might have other files such as clustering or regression.R depending on the project. The key idea is that since I have standard names I can go to any project and quickly find what I need.9. Your turn
Right. Let's get some practice.Create Your Free Account
or
By continuing, you accept our Terms of Use, our Privacy Policy and that your data is stored in the USA.