Skip to content

Commit

Permalink
[skip ci] use here::here() for R-raw/*.Rmd and render
Browse files Browse the repository at this point in the history
  • Loading branch information
Zhuoer Dong committed Apr 17, 2019
1 parent 1247d29 commit b131846
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 33 deletions.
23 changes: 11 additions & 12 deletions R-raw/data.Rmd
Original file line number Diff line number Diff line change
@@ -1,24 +1,27 @@
---
title: processing raw data to package data
date: "`r Sys.Date()`"
---

# preparation

```{r include=FALSE}
assertthat::assert_that(
knitr::current_input() %>% paste0('R-raw/', .) %>% file.exists(),
msg = 'Please set knitr root directory to project directory! You may try running `rmarkdown::render("data-raw/data.Rmd")` at project directory or clicking `Knit` button on the top of this document in RStudio.'
)
```{r knitr-setup, include=FALSE}
knitr::opts_knit$set(root.dir = here::here(''))
```



# clean

```{r clean, include=FALSE}
dir('data', full.names = T) %>% file.remove()
dir(here::here('data'), full.names = T) %>% file.remove()
rm(list = ls(envir = globalenv(), all = T))
```



# Process raw data



# Afterward

```{r reinstall}
Expand All @@ -28,7 +31,3 @@ roxygen2::roxygenize() # you may also have edited data documentation
system('R CMD INSTALL --no-multiarch --with-keep.source .')
devtools::reload() # now you can use the new data in current R session
```




34 changes: 13 additions & 21 deletions R-raw/vignettes.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,27 @@ title: build package vignettes
---


# preparation

```{r include=FALSE}
assertthat::assert_that(
knitr::current_input() %>% paste0('R-raw/', .) %>% file.exists(),
msg = 'Please set knitr root directory to project directory! You may try running `rmarkdown::render("data-raw/data.Rmd")` at project directory or clicking `Knit` button on the top of this document in RStudio.'
)
```


# Build vignettes

```{r build-vignettes}
rmd_vignettes <- dir('vignettes', 'Rmd$', full = T);
if (length(rmd_vignettes) > 0L) {
for (rmd_vignette in rmd_vignettes) {
callr::r_vanilla(
function(input_file) {options(encoding = 'UTF-8'); rmarkdown::render(input_file)},
list(rmd_vignette), .libPaths(), show = T
)
}
dir('vignettes', 'html$') %>% {file.copy(paste0('vignettes/', .), paste0('inst/doc/', .), overwrite = T)}
for (rmd_vignette in dir(here::here('vignettes'), 'Rmd$', full = T)) {
callr::r_vanilla(
function(input_file) {rmarkdown::render(input_file)},
list(rmd_vignette), .libPaths(), show = T
)
}
dir(here::here('vignettes'), 'html$') %>%
{file.copy(
paste0(here::here('vignettes/'), .),
paste0(here::here('inst/doc/'), .),
overwrite = T
)}
```



# Afterward

```{r reinstall}
Expand All @@ -39,4 +32,3 @@ if (length(rmd_vignettes) > 0L) {
system('R CMD INSTALL --no-multiarch --with-keep.source .')
devtools::reload() # now you can view the vignettes
```

0 comments on commit b131846

Please sign in to comment.