To make my code modular, I wrote a R script for plotting data, which invokes an R script to prepare the data (to be plotted):
The document.Rmd
file contains a line source('./R/customPlot.R')
and this script in turns contains a line source('./prepareData.R')
.
Running the document.Rmd
gives me an error message that ./prepareData.R
was not found, which could easily be fixed by changing the line in the script customPlot.R
to source('./R/prepareData.R
).
In this case, however, I could no longer just run customPlot.R
on it's own to visually check its output.
My folder structure looks like this:
project/
Rmd/
document.Rmd # calls source('./R/customPlot.R')
R/
customPlot.R # calls source('./prepareData.R')
prepareData.R
By searching the web, I learned that generating a package of my code might be a possible solution. Although my project is a bit larger, I wanted to ask whether it's worth the overhead. After all, the majority of files in my project are data and actually few of them are code.