Skip to content

Instantly share code, notes, and snippets.

@tjmahr
Last active February 25, 2016 20:32
Show Gist options
  • Select an option

  • Save tjmahr/06492d003724686b102a to your computer and use it in GitHub Desktop.

Select an option

Save tjmahr/06492d003724686b102a to your computer and use it in GitHub Desktop.
knitr inline todos
---
title: "knitr todos"
author: "Tristan Mahr"
date: "February 25, 2016"
output:
html_document:
keep_md: yes
---
```{r}
# function to display text inline
md_mono <- function(x) sprintf("`%s`", x)
# log todos to a yaml file
todos <- list(date = format(Sys.Date()))
todo <- function(note, note_fun = md_mono, outfile = "todos.yaml") {
note <- stringr::str_replace_all(note, "\\n", " ")
todos <<- c(todos, note)
writeLines(yaml::as.yaml(todos), outfile)
note_fun(note)
}
```
Thirty children participated in the study. `r todo("N children with hearing
loss")` had to be excluded, and `r todo("N parent reported late talkers")` had
to be excluded.
```{r}
str(todos)
```
```{r}
cat(yaml::as.yaml(todos))
```

knitr todos

Tristan Mahr
February 25, 2016

# function to display text inline
md_mono <- function(x) sprintf("`%s`", x)

# log todos to a yaml file
todos <- list(date = format(Sys.Date()))
todo <- function(note, note_fun = md_mono, outfile = "todos.yaml") {
  note <- stringr::str_replace_all(note, "\\n", " ")
  todos <<- c(todos, note)
  writeLines(yaml::as.yaml(todos), outfile)
  note_fun(note)
}

Thirty children participated in the study. N children with hearing loss had to be excluded, and N parent reported late talkers had to be excluded.

str(todos)
## List of 3
##  $ date: chr "2016-02-25"
##  $     : chr "N children with hearing loss"
##  $     : chr "N parent reported late talkers"
cat(yaml::as.yaml(todos))
## date: '2016-02-25'
## '': N children with hearing loss
## '': N parent reported late talkers
date: '2016-02-25'
'': N children with hearing loss
'': N parent reported late talkers
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment