Skip to content

Commit

Permalink
add yaml header to R test file.
Browse files Browse the repository at this point in the history
treat it properly in the code
update vignettes.
Fix #41
  • Loading branch information
gfinak committed Aug 1, 2018
1 parent fc806f7 commit 2826901
Show file tree
Hide file tree
Showing 5 changed files with 734 additions and 195 deletions.
11 changes: 7 additions & 4 deletions R/processData.R
Expand Up @@ -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,
Expand Down
5 changes: 5 additions & 0 deletions inst/extdata/tests/rfileTest.R
@@ -1 +1,6 @@
#' ---
#' title: Sample report from R script
#' author: Greg Finak
#' date: August 1, 2018
#' ---
data <- runif(100)
17 changes: 17 additions & 0 deletions vignettes/usingDataPackageR.Rmd
Expand Up @@ -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.

Expand Down

0 comments on commit 2826901

Please sign in to comment.