KentonWhite / ProjectTemplate

A template utility for R projects that provides a skeletal project.
http://projecttemplate.net
GNU General Public License v3.0
622 stars 159 forks source link

Feature Request: Create file templates #99

Closed biocyberman closed 6 years ago

biocyberman commented 10 years ago

I would like to put a request on a feature that allows creating various file templates:

Currently the project configuration file config/global.dcf file is good to load the project as a whole and any scripts therein will not have to handle library import and data preparation. But if we just one to run one script in with R --vanilla for example, this would not work because libraries and data are missing. My suggestion is to implement a function like create.file.template(name = "file_name", dir = "munge", type = c("R", "Rmd")[1], library = c("dplyr", "lubridate", "ggplot2"), data = "my_dataset1"). The function then create a file with appropriate content template based on input parameters. For example, with the aforementioned command, it would create an R file under munge directory with the beginning of the file like so:

# Project: My Test Project
# File: file_name.R
# Date Created: today()
# Author: TheAuthor
# Email: dummy@email.com
# Anything else from global.dcf

library(dplyr)
library(lubridate)
library(ggplot2)

my_dataset1 <- read.csv("../data/my_dataset1.csv")

This way the file is both consistent with project structure and self-contained.

Would this be something worth doing?

krlmlr commented 10 years ago

I'm not sure. I always use reload.project() as first statements in the scripts in src/ -- this doesn't make them self-contained, but you need the data files anyway. Of course, this only works with munging: FALSE and everything in cache.

biocyberman commented 10 years ago

I think it would be better if create.file.template is implemented. But thanks for mentioning of reload.project() at the head of every src file.

krlmlr commented 10 years ago

My main concern is that the information becomes out of date if you change your configuration. However, I'd review a pull request that creates a header with a comment and the statements calls

library(ProjectTemplate)
reload.project()

.