Skip to content

Commit

Permalink
Resolved issue with 'render_rmd()', which was not overwriting previou…
Browse files Browse the repository at this point in the history
…sly rendered files.
  • Loading branch information
kamapu committed Apr 20, 2024
1 parent c01479b commit d142f0f
Show file tree
Hide file tree
Showing 7 changed files with 119 additions and 89 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Package: yamlme
Version: 0.1.2
Version: 0.1.2.9001
Encoding: UTF-8
Title: Writing 'YAML' Headers for 'R-Markdown' Documents
Authors@R: c(
Expand Down Expand Up @@ -29,7 +29,7 @@ URL: https://github.com/kamapu/yamlme,
https://kamapu.github.io/yamlme/
BugReports: https://github.com/kamapu/yamlme/issues
VignetteBuilder: knitr
RoxygenNote: 7.2.1
RoxygenNote: 7.3.1
Collate:
'imports.R'
'classes.R'
Expand Down
43 changes: 26 additions & 17 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,38 +1,47 @@
yamlme 0.1.2
============
# yamlme 0.1.3

### Bug Fixes

- Function `render_rmd()` is now overwritten previous versions of rendered
files.



# yamlme 0.1.2

### Improvements

* All duties regarding reading and writing yaml head were passed to package
- All duties regarding reading and writing yaml head were passed to package
[`yaml`](https://biostat.app.vumc.org/wiki/Main/YamlR).
* A description for the class `rmd_doc` was added.
* Function `yamlme:::write_yaml()` is working recursively, based on discussions
- A description for the class `rmd_doc` was added.
- Function `yamlme:::write_yaml()` is working recursively, based on discussions
[here](https://stackoverflow.com/questions/61712575/how-to-run-function-on-the-deepest-level-only-in-a-nested-list) and [here](https://stackoverflow.com/questions/70272176/get-names-at-deepest-level-of-a-nested-list-in-r/)
* Parameters `temp_file` and `delete_temp` are deprecated.
* Function `render_rmd()` will write in the temporal directory and then move
- Parameters `temp_file` and `delete_temp` are deprecated.
- Function `render_rmd()` will write in the temporal directory and then move
resulting files to the working directory, if necessary.
* If not included, extension *.Rmd will be automatically added to `filename`
- If not included, extension *.Rmd will be automatically added to `filename`
in `write_rmd()`.
* Parameter `output_file` in function `render_rmd()` may include the .Rmd
- Parameter `output_file` in function `render_rmd()` may include the .Rmd
extension or not and the file can be written in the temporary directory or
any other path.
* Replacement methods for function `as.list()` (function `as<-`).
- Replacement methods for function `as.list()` (function `as<-`).



yamlme 0.1.1
============
# yamlme 0.1.1

### New Features

* A `print()` method for `rmd_doc` objects.
* An `update()` method for `rmd_doc` objects.
- A `print()` method for `rmd_doc` objects.
- An `update()` method for `rmd_doc` objects.

### Improvements

* Objects of class `rmd_doc` are now structured as lists instead of character
- Objects of class `rmd_doc` are now structured as lists instead of character
vectors.
* Output of function `read_rmd()` is an object of class `rmd_doc` instead of plain
- Output of function `read_rmd()` is an object of class `rmd_doc` instead of plain
character vector.

### Bug Fixes

* Dash vectors may also be of length 1
- Dash vectors may also be of length 1
9 changes: 5 additions & 4 deletions R/print.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ print2text <- function(x) {
collapse = ""
)
} else {
x$header <- paste0(c(
"---\n", "# No header in this document!\n", "---\n\n"
),
collapse = ""
x$header <- paste0(
c(
"---\n", "# No header in this document!\n", "---\n\n"
),
collapse = ""
)
}
if ("body" %in% names(x)) {
Expand Down
5 changes: 4 additions & 1 deletion R/render_rmd.R
Original file line number Diff line number Diff line change
Expand Up @@ -82,5 +82,8 @@ render_rmd.rmd_doc <- function(input, output_file, delete_rmd = TRUE, ...) {
if (delete_rmd) {
files_tmp <- files_tmp[!grepl(".Rmd", files_tmp, fixed = TRUE)]
}
file.copy(from = file.path(tempdir(), files_tmp), to = dirname(output_file))
file.copy(
from = file.path(tempdir(), files_tmp), to = dirname(output_file),
overwrite = TRUE
)
}
33 changes: 18 additions & 15 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,16 @@ output:

```{r,echo=FALSE}
knitr::opts_chunk$set(
collapse=TRUE,
comment="#>",
fig.path="man/figures/"
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/"
)
```

# yamlme

<!-- badges: start -->
[![cran checks](https://badges.cranchecks.info/worst/yamlme.svg)](https://cran.r-project.org/web/checks/check_results_yamlme.html)
[![CRAN_Status_Badge](http://www.r-pkg.org/badges/version/yamlme)](https://cran.r-project.org/package=yamlme)
[![DOI](https://zenodo.org/badge/297735831.svg)](https://zenodo.org/badge/latestdoi/297735831)
<br>
Expand Down Expand Up @@ -57,18 +58,20 @@ in R-objects.

```{r}
my_document <- list(
title = "Mi First Document",
author = "My Name",
output = "html_document",
body = txt_body(
"# Starting a working day",
"",
"At the beginning of every day I will do:",
"",
"- Say everyone \"Good morning!\"",
"- Start the coffe mashine",
"- Start the computer",
"- Read mails"))
title = "Mi First Document",
author = "My Name",
output = "html_document",
body = txt_body(
"# Starting a working day",
"",
"At the beginning of every day I will do:",
"",
"- Say everyone \"Good morning!\"",
"- Start the coffe mashine",
"- Start the computer",
"- Read mails"
)
)
my_document <- as(my_document, "rmd_doc")
my_document
```
Expand Down
33 changes: 18 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@

<!-- README.md is generated from README.Rmd. Please edit that file -->

<!-- Use snippet 'render_markdown' for it -->

# yamlme

<!-- badges: start -->

[![CRAN\_Status\_Badge](http://www.r-pkg.org/badges/version/yamlme)](https://cran.r-project.org/package=yamlme)
[![cran
checks](https://badges.cranchecks.info/worst/yamlme.svg)](https://cran.r-project.org/web/checks/check_results_yamlme.html)
[![CRAN_Status_Badge](http://www.r-pkg.org/badges/version/yamlme)](https://cran.r-project.org/package=yamlme)
[![DOI](https://zenodo.org/badge/297735831.svg)](https://zenodo.org/badge/latestdoi/297735831)
<br>
[![R-CMD-check](https://github.com/kamapu/yamlme/workflows/R-CMD-check/badge.svg)](https://github.com/kamapu/yamlme/actions)
[![Codecov test
coverage](https://codecov.io/gh/kamapu/yamlme/branch/master/graph/badge.svg)](https://codecov.io/gh/kamapu/yamlme?branch=master)
<br>
[![CRAN\_downloads](http://cranlogs.r-pkg.org/badges/yamlme)](https://cran.r-project.org/package=yamlme)
[![CRAN_downloads](http://cranlogs.r-pkg.org/badges/yamlme)](https://cran.r-project.org/package=yamlme)
[![total
downloads](http://cranlogs.r-pkg.org/badges/grand-total/yamlme)](https://cran.r-project.org/package=yamlme)
<!-- badges: end -->
Expand Down Expand Up @@ -48,18 +49,20 @@ This package aims to save documents with their respective settings

``` r
my_document <- list(
title = "Mi First Document",
author = "My Name",
output = "html_document",
body = txt_body(
"# Starting a working day",
"",
"At the beginning of every day I will do:",
"",
"- Say everyone \"Good morning!\"",
"- Start the coffe mashine",
"- Start the computer",
"- Read mails"))
title = "Mi First Document",
author = "My Name",
output = "html_document",
body = txt_body(
"# Starting a working day",
"",
"At the beginning of every day I will do:",
"",
"- Say everyone \"Good morning!\"",
"- Start the coffe mashine",
"- Start the computer",
"- Read mails"
)
)
my_document <- as(my_document, "rmd_doc")
my_document
#> ---
Expand Down
81 changes: 46 additions & 35 deletions vignettes/yamlme-intro.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,10 @@ The description will start with a vertical line in the yaml header.

```{r}
my_document <- list(description = paste0(c(
"This text starts with a vertical line",
"and will be thus used as a description",
"in the head."), collapse = "\n"))
"This text starts with a vertical line",
"and will be thus used as a description",
"in the head."
), collapse = "\n"))
as(my_document, "rmd_doc")
```

Expand All @@ -64,10 +65,11 @@ sometimes required for PDF documents.

```{r}
my_document <- list("header-includes" = c(
"\\usepackage{titling}",
"\\pretitle{\\begin{flushleft}\\LARGE\\textbf}",
"\\posttitle{\\end{flushleft}}",
"\\sffamily"))
"\\usepackage{titling}",
"\\pretitle{\\begin{flushleft}\\LARGE\\textbf}",
"\\posttitle{\\end{flushleft}}",
"\\sffamily"
))
as(my_document, "rmd_doc")
```

Expand All @@ -83,12 +85,16 @@ The following is a more complex map using embedded lists.

```{r}
my_document <- list(
author = list(
list(
name = "Miguel Alvarez",
url = "https://kamapu.github.io/"),
list(
name = "Bisrat H. Gebrekhidan")))
author = list(
list(
name = "Miguel Alvarez",
url = "https://kamapu.github.io/"
),
list(
name = "Bisrat H. Gebrekhidan"
)
)
)
as(my_document, "rmd_doc")
```

Expand All @@ -103,18 +109,20 @@ Here there is an example of a full Rmarkdown document.

```{r}
my_document <- list(
title = "Mi First Document",
author = "My Name",
output = "html_document",
body = txt_body(
"# Starting a working day",
"",
"At the beginning of every day I will do:",
"",
"- Say everyone \"Good morning!\"",
"- Start the coffe mashine",
"- Start the computer",
"- Read mails"))
title = "Mi First Document",
author = "My Name",
output = "html_document",
body = txt_body(
"# Starting a working day",
"",
"At the beginning of every day I will do:",
"",
"- Say everyone \"Good morning!\"",
"- Start the coffe mashine",
"- Start the computer",
"- Read mails"
)
)
my_document <- as(my_document, "rmd_doc")
```

Expand All @@ -132,13 +140,15 @@ written by `write_rmd()`.

```{r}
my_template <- list(
title = "Example HTML document",
author = "My Self",
output = "html_document",
body = txt_body(
"# Introduction",
"",
"This is just an example."))
title = "Example HTML document",
author = "My Self",
output = "html_document",
body = txt_body(
"# Introduction",
"",
"This is just an example."
)
)
my_template <- as(my_template, "rmd_doc")
my_template
```
Expand All @@ -147,8 +157,9 @@ We can also modify the template to adapt the output or the template of the
document.

```{r}
my_template <- update(my_template,
title = "Example PDF document",
output = "pdf_document")
my_template <- update(my_template,
title = "Example PDF document",
output = "pdf_document"
)
my_template
```

0 comments on commit d142f0f

Please sign in to comment.