Workflow
How you organise yourself when doing R will make it easier for you if you need to go back to your script weeks or years after, and to share with others people.
There is different workflow that you can do. At first, when I was
working on a project, I was using a simple folder named analyses
and
put everything in it with obscure name such as spatial analyses.R
or
canopy area analyses.R
, etc. I was also putting all the outputs
(Figures, tables, maps) in the same working directory as the .R scripts.
I think, this make it harder to find again some figures that you did made.
Now I am using since a couple of year another workflow. I first used
number before each names to know which script I need to run at first
like 1 data upload.R
, 2 function point pattern.R
and 3 final
results.R
.
For the outputs, I have .RData
saving files in the working directory,
but all my Figures are in different folder. Thus, for example, I have
a path like this ./living/NA/normal/replicate/Lmm graph/
with every
figures of the L_mm functions (a spatial pattern function) for the
replicate normal NA (no marks) and living patterns.
I have a little script that help in R for checking if the path is here and make a new folder or not if it already exist.
Here is the little script will check for the path /Project X/Analyses/results RandomForest
:
You can even add it in a for
loop like this:
Here it will check for three different paths in the same subfolder
results RandomForest
/Project X/Analyses/results RandomForest/temperature
/Project X/Analyses/results RandomForest/slope
/Project X/Analyses/results RandomForest/patterns
and save in each folder a file names varialbes_temperature.pdf
(or slope.pdf
or patterns.pdf) in the folder temperature (or slope or patterns).
The outputs figures should look like this: