From 282690148eef9bb4318509fc66e65d9c3b590720 Mon Sep 17 00:00:00 2001 From: gfinak Date: Wed, 1 Aug 2018 11:21:09 -0700 Subject: [PATCH] add yaml header to R test file. treat it properly in the code update vignettes. Fix #41 --- R/processData.R | 11 +- inst/extdata/tests/rfileTest.R | 5 + vignettes/usingDataPackageR.Rmd | 17 + vignettes/usingDataPackageR.html | 587 ++++++++++++++++++++++--------- vignettes/usingDataPackageR.md | 309 ++++++++++++++-- 5 files changed, 734 insertions(+), 195 deletions(-) diff --git a/R/processData.R b/R/processData.R index 90001cc..4d9c262 100644 --- a/R/processData.R +++ b/R/processData.R @@ -274,16 +274,19 @@ DataPackageR <- function(arg = NULL, deps = TRUE) { assert_that(file.exists(r_files[i]), msg = paste0("File: ",r_files[i]," does not exist!")) lines <- readLines(r_files[i]) - lines <- c("---", + # do we likely have a yaml header? If not, add one. + if (lines[1] != "---") { + lines <- c("---", paste0("title: ",basename(r_files[i])), paste0("author: ", Sys.info()["user"]), paste0("date: ", Sys.Date()), "---", "", lines) - con <- file(r_files[i]) - writeLines(lines, con = con, sep = "\n") - close(con) + con <- file(r_files[i]) + writeLines(lines, con = con, sep = "\n") + close(con) + } } rmarkdown::render( input = r_files[i], envir = dataenv, diff --git a/inst/extdata/tests/rfileTest.R b/inst/extdata/tests/rfileTest.R index 1d699dd..8bd45f4 100644 --- a/inst/extdata/tests/rfileTest.R +++ b/inst/extdata/tests/rfileTest.R @@ -1 +1,6 @@ +#' --- +#' title: Sample report from R script +#' author: Greg Finak +#' date: August 1, 2018 +#' --- data <- runif(100) \ No newline at end of file diff --git a/vignettes/usingDataPackageR.Rmd b/vignettes/usingDataPackageR.Rmd index 9f6ecd6..10bf2b8 100644 --- a/vignettes/usingDataPackageR.Rmd +++ b/vignettes/usingDataPackageR.Rmd @@ -144,6 +144,23 @@ Similarly: Raw data sets that are stored externally (outside the data package source tree) can be constructed relative to the `project_path()`. +### YAML header metadata for R files and Rmd files. + +If your processing scripts are Rmd files, the usual yaml header for rmarkdown documents should be present. + +If you have Rmd files, you can still include a yaml header, but it should be commented with `#'` and it should be at the top of your R file. For example, a test R file in the DataPackageR package looks as follows: + +``` +#'--- +#'title: Sample report from R script +#'author: Greg Finak +#'date: August 1, 2018 +#'--- +data <- runif(100) +``` + +This will be converted to an Rmd file with a proper yaml header, which will then be turned into a vignette and properly indexed in the built package. + ## Build the data package. diff --git a/vignettes/usingDataPackageR.html b/vignettes/usingDataPackageR.html index c54f6c6..324405a 100644 --- a/vignettes/usingDataPackageR.html +++ b/vignettes/usingDataPackageR.html @@ -291,6 +291,7 @@

2018-08-01

  • A few words abou the YAML config file
  • Where do I put my raw datasets?
  • An API to read raw data sets from within an R or Rmd procesing script.
  • +
  • YAML header metadata for R files and Rmd files.
  • Build the data package.